Title: Query Loop Parameters
Last modified: October 16, 2022

---

# Query Loop Parameters

 *  Resolved [Kx](https://wordpress.org/support/users/krisphelps/)
 * (@krisphelps)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/query-loop-arguments/)
 * Hi There!
 * It would be awesome to have an “AND” option added to the taxonomies selectors
   in the Query Loop parameters.
 * Right now, it operates on an “OR” basis, and looking at the WP Query class code,
   it should be simple to swap the comma delimiter with a plus sign, then UI-wise,
   have “AND/OR” buttons that function as a toggle defaulted to “OR” as that’s the
   functionality that you seem to expect most people to need.
 * Example Use Case: A music site wants to create a page dedicated to a specific
   rock guitarist. They have a section talking about rock guitars and want to include
   their latest posts about rock guitars. They create a Query Loop and specify the
   tags “rock” and “guitar.”
 * With the current behavior, the Query Loop will just output the latest articles
   about rock OR guitars, but not articles that are tagged specifically with both
   the “rock” and “guitar” tags. So, the latest article titled “Top 10 Rock Drummers
   of All Time” is output because it is tagged “rock.”
 * Hopefully, this makes sense and seems like natural functionality to include.
 * Even better, if there is a way this is already possible, I’m happy to be wrong!
   🙂
 * I’m a happy GeneratePress Pro user and I’d also be interested in seeing side-
   by-side comparisons of what is possible between GenerateBlocks and GenerateBlocks
   Pro.
    -  This topic was modified 3 years, 7 months ago by [Kx](https://wordpress.org/support/users/krisphelps/).
      Reason: adding clarification
    -  This topic was modified 3 years, 7 months ago by [Kx](https://wordpress.org/support/users/krisphelps/).

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

 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/query-loop-arguments/#post-16104166)
 * Hi there,
 * I think this makes sense 🙂 We’ll see what we can do.
 * For now, you can remove the taxonomy parameter from the query loop, and add a
   CSS class to the Grid Block of the Query loop block, eg. `rock_guitar`, then 
   add this PHP snippet:
 *     ```
       add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
           if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'rock_guitar' ) !== false ) {
               $query_args['tag'] =  'rock+guitar' ;
           }
   
           return $query_args;
       }, 10, 2 );
       ```
   
 * You can replace `rock` and `guitar` with any other tag slugs, or add more tags.
   For example, `$query_args['tag'] = 'rock+guitar+artist'`, so the query will show
   the posts which have all 3 tags.
 *  Thread Starter [Kx](https://wordpress.org/support/users/krisphelps/)
 * (@krisphelps)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/query-loop-arguments/#post-16104248)
 * Hi Ying!
 * Thank you so much for the quick response. I’ll give that a try.
 * Quick question, as I run into this frequently with GeneratePress. I *adore* the
   elements functionality, but find that I might possibly be using it as a cure-
   all.
 * For example, my first thought on your answer was to add that code to a Hook element
   and execute the PHP. Do you have any guidance when it’s best to use a hook element
   with execute PHP versus using functions.php versus a custom plugin?
 * I sincerely appreciate your help.
 * Thanks,
    Kris
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/query-loop-arguments/#post-16104268)
 * The PHP code added to a hook element needs to be outputting something, so you
   are basically inserting some HTML generated by the PHP code into your site.
 * But the code I provided is not this case, it’s a function, that needs to be added
   to `functions.php` or the code snippet plugin.
 * Hope I made it clear 🙂
 *  Thread Starter [Kx](https://wordpress.org/support/users/krisphelps/)
 * (@krisphelps)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/query-loop-arguments/#post-16104272)
 * That’s perfectly clear. Thank you.
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/query-loop-arguments/#post-16107593)
 * You are welcome 🙂
 *  [fernandoazarcon2](https://wordpress.org/support/users/fernandoazarcon2/)
 * (@fernandoazarcon2)
 * [3 years, 5 months ago](https://wordpress.org/support/topic/query-loop-arguments/#post-16311691)
 * Hi there! We haven’t heard back from you for a while now so we’re going to go
   ahead and set this topic as resolved. Feel free to reply if you need any more
   help.

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

The topic ‘Query Loop Parameters’ is closed to new replies.

 * ![](https://ps.w.org/generateblocks/assets/icon.svg?rev=3239461)
 * [GenerateBlocks](https://wordpress.org/plugins/generateblocks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/generateblocks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/generateblocks/)
 * [Active Topics](https://wordpress.org/support/plugin/generateblocks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/generateblocks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/generateblocks/reviews/)

## Tags

 * [arguments](https://wordpress.org/support/topic-tag/arguments/)
 * [parameters](https://wordpress.org/support/topic-tag/parameters/)
 * [taxonomies](https://wordpress.org/support/topic-tag/taxonomies/)

 * 6 replies
 * 3 participants
 * Last reply from: [fernandoazarcon2](https://wordpress.org/support/users/fernandoazarcon2/)
 * Last activity: [3 years, 5 months ago](https://wordpress.org/support/topic/query-loop-arguments/#post-16311691)
 * Status: resolved