• Hi, recently updated my wordpress to 5.5.3, before this update, i think my query work fine, but now have problem on it. I was created a custom post type like ‘my_post_type’ and wan’t search in this post type list. this is my arguments for WP_Query:

    $args = [
    ‘post_type’ => $this->getPostTypeId(),
    ‘posts_per_page’ => $request->count,
    ‘offset’ => $request->getPaginationOffset(),
    ‘post_status’ => ‘publish’,
    ‘s’ => $request->keyword,
    ];

    When remove search (‘s’) request, the query retrieve my custom post type list, but when add the search the query search in ‘post’ post type (default post type). How can search on post that based on my custom post type?

    • This topic was modified 4 years, 4 months ago by pedramfadaei.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Sorry for the slow reply. Since you code is out of context from its class, it’s hard to say what the problem is. Apparently $this->getPostTypeId() isn’t returning what you expect it to; or some other code is altering search queries, through “pre_get_posts” for example.

    Try hard coding the post type to search: 'post_type'=> array('my_post_type',),

    If that doesn’t work, something else is altering the query after it’s instantiated.

Viewing 1 replies (of 1 total)
  • The topic ‘Search in custom post type’ is closed to new replies.