• Resolved Gald

    (@ager2014)


    Hello,

    I would like to modify the search in my website in order to seek in posts, pages, a custom post type and its custom post fields.

    The problem is that when I add the custom fields search with meta_query, it gives me the custom post types that match, but it does not return any page or post, because logically those do not have any custom post field.

    Here is the code:

    $args = array(
    	'numberposts'	=> -1,
    	'post_type'		=> array('obra','post','page'),
    	'meta_query'	=> array(
    		'relation'		=> 'OR',
    		array(
    			'key'		=> 'ano',
    			'value'		=> get_search_query(false),
    			'compare'	=> 'LIKE'
    		),
    		array(
    			'key'		=> 'estado',
    			'value'		=> get_search_query(false),
    			'compare'	=> 'LIKE'
    		),
    		array(
    			'key'		=> 'tamano',
    			'value'		=> get_search_query(false),
    			'compare'	=> 'LIKE'
    		)
    	)
    );
    
    // query
    $the_query = new WP_Query( $args );

    Do you know can I solve this situation? Merge of arrays? Modifying the query itself, etc…

    At the moment I’m not using any plugin for the search. Before I tried another strategy, because the other day it did not work, and looked difficult to solve.

    https://www.ads-software.com/support/topic/search-also-in-custom-post-type-fields?replies=2

    Thanks so much in advance!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Mix custom post type and posts, pages on a search’ is closed to new replies.