• I’m flummoxed. Although I thought I implemented a post type restriction correctly in WP_Query, I’m still getting returned posts that are NOT in my post_type.

    Here’s the sitch:

    I have a custom post type (“providers”) created through Custom Post Type UI version 0.8.2 .

    I want to display *only* providers (not posts) that match a search term stored in $providername. Here’s my code. Note that I have Relevanssi enabled, which is why there’s some conditional code, but whether it’s activated or not, I’m still getting a search result that includes posts as well as providers. I want providers only, and not other post types, in this case the standard WP “post”. What am I missing?

    if (!empty($providername)) {
              $args = array(
                'post_type' => 'providers',
                's' => $providername,
                'posts_per_page' => -1
              );
              if (function_exists(relevanssi_do_query)) {
                $blog_query = new WP_Query($args);
                relevanssi_do_query($blog_query);
              }
              else {
                $blog_query = new WP_Query($args);
            }
        }
Viewing 1 replies (of 1 total)
  • Is it possible that something else (a filter on pre_get_posts or the like is mucking with your query? can you try to deactivate plugins / look through any custom theme code for possible culprits?

    Whenever I have these head scratching moments, it’s usually another piece of code or a plugin that’s causing problems.

Viewing 1 replies (of 1 total)
  • The topic ‘post_type restriction on wp_query doesn't work?’ is closed to new replies.