0

I am trying to search through my custom post types. I am using this code which using debug, I know is being fired.

function search_post_type($wp_query) {
    if (is_search()) {
        $wp_query->set('post_type', array("myposts"));
    }
}
add_filter('pre_get_posts', 'search_post_type');

However, the search just searches on the default post types, ignoring myposts - which is the only one I want it to search.

Where is the actual search performed (data queried) so I can check if the custom post type is getting to the right place.

Thank you

  • You can add a filter to posts_where and debug the $where clause value to see if the query is changed to the desired post type. – majick Oct 10 '19 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.