Title: Using two meta_keys
Last modified: July 10, 2019

---

# Using two meta_keys

 *  Resolved [jjangbi](https://wordpress.org/support/users/jjangbi/)
 * (@jjangbi)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/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.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/using-two-meta_keys/#post-11722006)
 * Hi [@jjangbi](https://wordpress.org/support/users/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,
 *  Thread Starter [jjangbi](https://wordpress.org/support/users/jjangbi/)
 * (@jjangbi)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/using-two-meta_keys/#post-11722210)
 * 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, 11 months ago by [jjangbi](https://wordpress.org/support/users/jjangbi/).
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/using-two-meta_keys/#post-11722374)
 * You could try this filter.
    [https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_query_args](https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_query_args)
 *     ```
       function 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.
 *  Thread Starter [jjangbi](https://wordpress.org/support/users/jjangbi/)
 * (@jjangbi)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/using-two-meta_keys/#post-11722415)
 * 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!
 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/using-two-meta_keys/#post-11722419)
 * Perfect! thanks for following up.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Using two meta_keys’ is closed to new replies.

 * ![](https://ps.w.org/ajax-load-more/assets/icon-256x256.png?rev=2944639)
 * [Ajax Load More – Infinite Scroll, Load More, & Lazy Load](https://wordpress.org/plugins/ajax-load-more/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ajax-load-more/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ajax-load-more/)
 * [Active Topics](https://wordpress.org/support/plugin/ajax-load-more/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ajax-load-more/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ajax-load-more/reviews/)

## Tags

 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [meta_key](https://wordpress.org/support/topic-tag/meta_key/)
 * [sort](https://wordpress.org/support/topic-tag/sort/)

 * 5 replies
 * 2 participants
 * Last reply from: [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/using-two-meta_keys/#post-11722419)
 * Status: resolved