Viewing 20 posts - 1 through 20 (of 20 total)
  • Author
    Posts
  • #487008

    Hi,
    on https://kriesi.at/support/topic/portfolio-items-with-redirects-in-search-results/ you describe how to remove the portfolio post type from the search results.
    May we also exclude a certain portfolio category (and its appropriate translated categories) from the search results?
    Thanks, Bernd

    #487149

    Hey profil77!

    Please add following code to Functions.php file in Appearance > Editor

    
    add_filter( 'pre_get_posts' , 'search_exc_cats' );
    function search_exc_cats( $query ) {
    
    if( $query->is_admin )
    return $query;
    
    if( $query->is_search ) {
    $query->set( 'category__not_in' , array( 30 ) );
    }
    return $query;
    }

    30 in array( 30 ) in the code is category ID. Replace it as needed
    Cheers!
    Yigit

    #488719

    Hi Yigit!
    Sorry, the code does not yet exclude a certain portfolio category. But at the moment that’s no problem:
    I need a few days to reorganize the portfolio items, then I will try again.
    Please let the post open for a while.
    Thanks, Bernd

    #489147

    We looking forward to hearing from you :)

    Regards,

    Josue

    #490581

    Hi Josue / Yigit!
    The code does not yet exclude special portfolio categories.
    Would you please have a look? You’ll find your code in Peter Dude’s Functions-Plugin.
    Thanks, Bernd

    #490601

    Hi!

    Please do try the following

    // search filter
    function fb_search_filter($query) {
    if ( !$query->is_admin && $query->is_search) {
    $query->set('post_type', array('portfolio') ); // id of page or post
    }
    return $query;
    }
    add_filter( 'pre_get_posts', 'fb_search_filter' );

    And do let us know if it worked out.

    Regards,
    Basilis

    #490622

    Hi Basilis!
    Thanks. Where exactly should I add the ids of the portfolio categories, that have to be excluded from the search?
    Regards, Bernd

    #490736

    Hey!

    Basilis’ code should exclude portfolio post type from search results.

    Cheers!
    Yigit

    #491033

    Hi!
    Thanks, but sorry:
    1) Basilis’ code doesn’t exclude the portfolio post type from search results.
    2) Please have a look at post # 490581: we don’t want to exclude all portfolio posts,
    but the posts of a special portfolio category.
    Thanks, Bernd

    #491102

    Hi!

    Try using this plugin:
    https://wordpress.org/plugins/simply-exclude/

    Cheers!
    Josue

    #491199

    O.K. thanks, I’ll try it with a plugin.
    Cheers, Bernd

    #491217

    You are welcome, glad to help :)

    Regards,
    Josue

    #1052862

    Hello everyone!
    I do not have many skills in English language, so I’m not sure if I understand if the codes above are correct for my case …
    I would like to hide only the portfolio categories from the search results, or replace them with the pages where the article is shown … is it possible?
    Thank you for your work!

    #1053163

    Hi Sachasilvestri,

    Well, this code should work in the case where you want a portfolio category not to appear in search results.

    Have you tried the code?

    Best regards,
    Victoria

    #1053197

    Hi Vittoria!
    Thanks for your reply, just a clarification … for search results .. do you mean the search on google or the internal search of the site?
    I need to hide the portfolio categories in the site’s internal search, that of the menu to be understood … ajax recearch … is this code right for my case?

    I put a demo link in private

    Thanks for your help!

    • This reply was modified 5 years, 11 months ago by Marco.
    #1053501

    Hi,

    Have you tried using the suggested plugin above?

    // https://wordpress.org/plugins/simply-exclude/

    You can remove the code if you decided to use the plugin.

    Best regards,
    Ismael

    #1054523

    Hi everybody ! Good day!

      the Basilis code unfortunately did not work

    The plug in indicated simply-exclude I saw that it has not been updated for 4 years. I’m really afraid of installing it.
      I’d rather hide links to all portfolio categories with code if possible. It can be relative to the whole site, I do not want links that send to portfolio categories. The text may remain, but not the link.

    Thank you very much for your patience and professionalism
    I await your response.

    #1056419

    Hi,

    Use this css code to remove the categories from the search results page.

    .search-results span.blog-categories.minor-meta {
        display: none !important;
    }

    Best regards,
    Ismael

    #1056425

    Fantastic ! it worked ! Thank you !!

    #1056461

    Hi,

    Great! We’ll close the thread now.

    Best regards,
    Ismael

Viewing 20 posts - 1 through 20 (of 20 total)
  • The topic ‘Remove portfolio category from search results?’ is closed to new replies.