Support

Account

Home Forums Backend Issues (wp-admin) Limit search results to ACF post type and category?

Unread

Limit search results to ACF post type and category?

  • I’ve set up an ACF post type called “encyclopedia” with a taxonomy category called “topics.” I now want to create an Elementor search results page that will only show post types of “encyclopedia” with the category of “topic.” I’ve tried making a PHP filter to restrict results to that criteria, but it’s still showing all entries that contain the entered search term from across the entire site.

    Below is the code to show any encyclopedia entries that meet the search criteria, but it’s showing all entries that contain the entered search criteria.

    Any suggestions for what I need to do differently?

    Thanks in advance for your help.

    if (!is_admin()) {
    function mv_search_filter($query) {
    if ($query->is_search) {
    $query->set('post_type', array( 'encyclopedia' ));
    }
    return $query;
    }
    add_filter('pre_get_posts','mv_search_filter');
    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.