This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

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 ]

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10391
    K15Lmk98K15Lmk98
    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’ => ‘>’
    )

    )

    );

    #10393
    Ernest MarcinkoErnest Marcinko
    Keymaster

    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.

    #10394
    K15Lmk98K15Lmk98
    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_

    #10397
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hmm, interesting.

    Can you try changing line 17 from:

    [php]’operator’ => ‘='[/php]

    to:

    [php]’operator’ => ‘ELIKE'[/php]

    or maybe

    [php]’operator’ => ‘LIKE'[/php]

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

    #10398
    K15Lmk98K15Lmk98
    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
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

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.