• Resolved tjldesigns

    (@tjldesigns)


    Hi there,

    I wonder if you can help, I need to add double quotes into the query below:

    meta_key=”post_authors” meta_value=”‘.get_the_ID().'” meta_compare=”LIKE” meta_type=”CHAR”

    So that it searches for ‘”‘ . get_the_ID() . ‘”‘ with the surrounding double quotes so it matches the following WP_Query

    ‘meta_query’ => array(
    array(
    ‘key’ => ‘post_authors’, // name of custom field
    ‘value’ => ‘”‘ . get_the_ID() . ‘”‘,
    ‘compare’ => ‘LIKE’
    )
    )

    This then ensures that it matches the values exactly within the field ie “123”, not just 123. This prevents a match for “1234”

    I’ve tried a couple of things but sadly no luck, any help would be so much appreciated :).

    Many thanks,
    TJ

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi @tjldesigns,
    If you need to use the double quotes you will have to use the alm_query_args filter.
    https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_query_args

    Hope that helps.

    Cheers,

    Thread Starter tjldesigns

    (@tjldesigns)

    Hi Darren,

    Thanks so much for your quick reply :).

    So, I have tried that, but I think I’m not doing something quite right… Can you see below, it’s now showing no results:

    https://www.taylorvinters.com/people/adam-bradley/?almquery=yes

    I’ve added the id to the shortcode: id=”people_insights” and this is the code I have added in functions.php (which I’ve tested as a standard WP_Query and it works), so not sure what I’m not doing quite right ??

    function alm_people_insights($args){

    $args[‘post_type’] = ‘post’;
    $args[‘meta_query’] = array(
    array(
    ‘key’ => ‘post_authors’,
    ‘value’ => ‘”‘ . get_the_ID() . ‘”‘,
    ‘compare’ => ‘LIKE’
    )
    );
    $args[‘tag__not_in’] = array( 34 );
    $args[‘ignore_sticky_posts’] = 1;

    return $args;

    }
    add_filter( ‘alm_query_args_people_insights’, ‘alm_people_insights’ );

    Thank you again,
    TJ

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

    (@dcooney)

    Hey,
    Your issue here would be get_the_ID() is not available in the ajax filter.

    You could get around this by passing the ID as a custom argument in your shortcode.

    
    [ajax_load_more custom_args="id:'.get_the_ID().'"]

    And then in your filter.

    function alm_people_insights($args){
    	
    	$id = $args['id']; // get the ID from the args
    
    	$args['post_type'] = 'post';
    	
    	$args['meta_query'] = array(
    		array(
    			'key' => 'post_authors',
    			'value' => '”' . $id . '”',
    			'compare' => 'LIKE'
    		)
    	);
    	$args['tag__not_in'] = array( 34 );
    	$args['ignore_sticky_posts'] = 1;
    	
    	return $args;
    
    }
    add_filter( 'alm_query_args_people_insights', 'alm_people_insights' );

    For next update Im goig to pass in the current post ID in the $args array

    • This reply was modified 7 years, 4 months ago by Darren Cooney.
    Thread Starter tjldesigns

    (@tjldesigns)

    Hi Darren,

    Thanks ever so much again for your reply, I’ve now implemented that update and it’s now working perfectly :).

    And yes, that will be great to include the ID in the args array for sure :).

    Many thanks again, and as always, great plugin!!
    TJ

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Double quotes in query’ is closed to new replies.