filter asp_query_args [ post_meta_filter: relation two custom field ]

Home Forums Product Support Forums Ajax Search Pro for WordPress Support filter asp_query_args [ post_meta_filter: relation two custom field ]

This topic contains 5 replies, has 2 voices, and was last updated by

 
Keymaster
5 years, 3 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10391

    Participant

    This is a machine translation.

    Good morning,
    I need to use the filter “asp_query_args” > “post_meta_filter”, to relate two custom fileds.

    Below the WP code and Ajax Search Pro – it DOES NOT WORK –

    You can use the relationship in Ajax Search Pro post_meta_filter ?

    For convenience I upload the code in text format.

    Thanks, Claudio_

    Code:
    // WordPress
    $date = date_create();
    $timestampAttuale = $date->getTimestamp();

    ……

    ‘meta_query’ => array(

    ‘relation’ => ‘OR’, // RELATION TWO CUSTOM FIELDS

    array( // senza scadenza
    ‘key’ => $GLOBALS[“prefixCmb2Azienda”] . ‘azienda_scadenza_no’,
    ‘value’ => ‘on’
    ),

    array( // data scadenza
    ‘key’ => $GLOBALS[“prefixCmb2Azienda”] . ‘azienda_scadenza_data’,
    ‘value’ => $timestampAttuale,
    ‘compare’ => ‘>’,
    ‘type’ => ‘NUMERIC’
    )

    ),

    // Ajax Search Pro
    function asp_query_args_change($args, $search_id) {

    $date = date_create();
    $timestampAttuale = $date->getTimestamp();

    $args[‘post_meta_filter’] = array(

    array(

    ‘relation’ => ‘OR’,

    array(
    ‘key’ => ‘cr_dati_azienda_scadenza_no’, // meta key
    ‘value’ => array( ‘on’ ), // mixed|array
    ‘operator’ => ‘=’
    ),
    array(
    ‘key’ => ‘cr_dati_azienda_scadenza_data’, // meta key
    ‘value’ => array( $timestampAttuale ), // mixed|array
    ‘operator’ => ‘>’
    )

    )

    );

    Attachments:
    You must be logged in to view attached files.
    #10393

    Hi!

    Thank you for uploading the code, it’s almost perfect, but I see a few issues. There are a few syntax errors and the return statement is missing. Also, the values cannot be arrays, unless for the “BETWEEN” operator.

    Try this changed version:

    This should hopefully work.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10394

    Participant

    Hi Ernest,
    thanks for the quick response.

    Unfortunately it does not work. Does not return any posts, but use only one custom field.

    Keys and values are correct, because they use the code Wp.

    The posts are of a CPT

    I am attaching two screenshots: “without_filter.png” and “filter.png”.

    If you can do something, otherwise it is the same.

    Thanks, Claudio_

    Attachments:
    You must be logged in to view attached files.
    #10397

    Hmm, interesting.

    Can you try changing line 17 from:

    'operator' => '='

    to:

    'operator' => 'ELIKE'

    or maybe

    'operator' => 'LIKE'

    The ‘=’ equality sign might not work as expected with string values.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #10398

    Participant

    Fantastic. It works.

    ASP plugin is great.

    Thanks Ernest 1000+

    I have another question, but for this I will open a new ticket.

    Good evening

    #10399
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘filter asp_query_args [ post_meta_filter: relation two custom field ]’ is closed to new replies.