I have a CPT that has multiple fields. I have a custom input form that takes a name as the input and this is stored in the $surname variable. I need to search my CPT for that name either as the CPT title or stored in one of the fields. I then need to display these one or more CPT's on a single custom template page.
This is my current code
$args1 = array( 's' => $surname, 'post_type' => 'studies' ); $query = new WP_Query ($args1);
This works fine and finds the name as I want BUT it also finds and returns pages that also have the same name on them. I have tried turning on exact in the query parameters and that stops displaying the pages but also stops searching the custom fields in the CPT.
I have spent several hours searching on here and on Google without success, I would have thought with specifying the post type as studies it would not search post type of page too.
Aucun commentaire:
Enregistrer un commentaire