admin管理员组

文章数量:1122832

I have a forum system where I created a custom post type, and I would like to have a search system for the topics, but I do not know what the structure would be, for example, how the file will be and the search form action.

I have a forum system where I created a custom post type, and I would like to have a search system for the topics, but I do not know what the structure would be, for example, how the file will be and the search form action.

Share Improve this question asked Aug 8, 2017 at 23:07 Carlos StevanatoCarlos Stevanato 51 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

I found an answer here, but it is treated as if I wanted a custom post type of a theme, in my case I created it as a Plugin, someone would have a light there of how I can create a search within a custom post type but that is Inside a plugin?

How to create a custom search for custom post type?

You should try this in your search


global $query_string;

wp_parse_str($query_string, $search_query);
//add post type.
$post_type = array('post_type'=>'your-custom-post-type');
$combine_search = array_merge($search_query,$post_type);

$search = new WP_Query($combine_search);

本文标签: Creating a search results page from a custom post type in a plugin