Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › filter asp_query_args [ post_meta_filter: relation two custom field ]
- This topic has 5 replies, 2 voices, and was last updated 9 years, 8 months ago by
Ernest Marcinko.
-
AuthorPosts
-
October 7, 2016 at 12:30 pm #10391
K15Lmk98
ParticipantThis 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’ => ‘>’
))
);
October 7, 2016 at 1:38 pm #10393Ernest Marcinko
KeymasterHi!
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.
October 7, 2016 at 2:49 pm #10394K15Lmk98
ParticipantHi 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_
October 7, 2016 at 2:58 pm #10397Ernest Marcinko
KeymasterHmm, 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.
October 7, 2016 at 3:15 pm #10398K15Lmk98
ParticipantFantastic. It works.
ASP plugin is great.
Thanks Ernest 1000+
I have another question, but for this I will open a new ticket.
Good evening
October 7, 2016 at 3:19 pm #10399Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- The topic ‘filter asp_query_args [ post_meta_filter: relation two custom field ]’ is closed to new replies.