• Hi,

    I am using the ajax-load-more plugin with a custom post type in the archive page.

    Now I want to do a search of that same post-type’s data and list out the results in the same archive page, (compatible with repeater templates too).

    I have written the code into my theme’s functions.php file but it doesn’t get any results when I search with a particular value.

    Below is my code:

    function meta_search_query($wp_query) {
    	global $wpdb, $post, $wp_query;
    	$query_args_meta = array(
    	'posts_per_page' => 5,
    	'post_type' => 'custom_posttyp',
    		'meta_query'=> array(
    			'relation' => 'OR',
    			array(
    				'key' => 'firstname',
    				'compare' => 'LIKE',
    				'value' => $_REQUEST['sterm'],
    			),
    			array(
    				'key' => 'location',
    				'compare' => 'LIKE',
    				'value' => $_REQUEST['sterm'],
    			),
    			array(
    				'key' => 'service_name',
    				'compare' => 'LIKE',
    				'value' => $_REQUEST['sterm'],
    			),
    		),
    	);
    	$wp_query->set('post_type', array('custom_posttyp'));
    	wp_reset_query();
    	wp_reset_postdata();
    	return $wp_query;
    }
    add_filter( 'pre_get_posts', 'meta_search_query');
    ## add_action( 'pre_get_posts', 'meta_search_query');

    Can anyone let me know why this doesn’t return any results?

    • This topic was modified 7 years, 6 months ago by vivekse2m.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi @ vivekse2m,
    I don’t have a lot of experience with pre_get_posts but i’m thinking tha since the request is being made with admin-ajax it doesn’t know what $_REQUEST['sterm']

    I think you should try to confirm the correct search value is being passed.

    Cheers,

    Thread Starter vivekse2m

    (@vivekse2m)

    Hi,

    I have yet another query, to which I need a real quick response.

    I have implemented a “Near Me” sorting query in the custom post type archive page, with which I am not getting the custom post array(with their respective post ids) as sort results.

    Now I cannot find a way to set that array of sort results as the main array of data for the repeater template (as repeater template works with posts coming from database directly).

    Also let me tell you, I have other sorting types also active in that same repeater template page, which I don’t want affected by the “sorting with location near me”.

    Can you assist ?

    Awaiting your response…

    Regards,
    Vivek Shah

    • This reply was modified 7 years, 6 months ago by vivekse2m.
    Plugin Author Darren Cooney

    (@dcooney)

    hi @vivekse2m,
    Im really not sure because I am a bit confused as to the functionality you are after.

    Ajax Load More uses WP_Query, so technically you should be able to query anything from your site as long as it’s queryable via WP_Query.

    Hope that helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Post Type Search with Repeater template is not working’ is closed to new replies.