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 Ernest Marcinko 7 years, 1 month ago.
- AuthorPosts
- October 7, 2016 at 12:30 pm #10391
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.October 7, 2016 at 1:38 pm #10393Hi!
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 :)
October 7, 2016 at 2:49 pm #10394Hi 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.October 7, 2016 at 2:58 pm #10397Hmm, 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 :)
October 7, 2016 at 3:15 pm #10398Fantastic. 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 #10399You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
The topic ‘filter asp_query_args [ post_meta_filter: relation two custom field ]’ is closed to new replies.