Using two meta_keys
-
Hi there. I have purchased ALM and I want to use two meta keys. My alm_render arg looks something like this:
... 'order' => $order, 'orderby' => $orderby, 'meta_key' => $meta_key, 'search' => $search, ...This is fine for sorting the search based on the meta key. However, I wish to also impose another meta key to filter the results to an ACF field (filter by posts of type ‘x’).
However, the shortcode generator to filter by an ACF field looks something like:
... 'meta_key' => $meta_key, 'meta_value' . => $meta_value, 'meta_compare' => "IN" ...This requires me to use the meta_key field that I was using for sorting. How would I use another meta_key so that one is for sorting and the other for filtering? I understand how to do this in a regular WP Query but not in the ALM render.
Thanks a bunch.
-
Hi @jjangbi,
Good question, this may not be possible using the shortcode params.How can you do this using a standard WP_Query? If you have an example, I can possibly provide a solution.
Cheers,
Well I was thinking something along the lines of using
meta_query = [ 'relation => AND' ... ]Now that I think about it, I am not too sure. Is there a way to catch the results after the query is done so that I can filter the results before they are paginated?
-
This reply was modified 6 years, 8 months ago by
jjangbi.
You could try this filter.
https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_query_argsfunction my_alm_listing($args, $id){ // $id = Current post/page ID where the ALM shortcode is found (alm_listing) $args['meta_key'] = 'key_name'; $args['orderby'] = 'meta_value'; $args['meta_query'] = array( array( 'key' => 'another_key_name', 'value' => 'the_value', 'compare' => '=' ) ); return $args; } add_filter( 'alm_query_args_alm_listing', 'my_alm_listing', 10, 2);Not sure if that would work.
Yep that did the trick. Setting the meta query in the shortcode doesn’t work but modifying it in that hook does. Thank you very much!
Perfect! thanks for following up.
-
This reply was modified 6 years, 8 months ago by
The topic ‘Using two meta_keys’ is closed to new replies.