• Resolved Kx

    (@krisphelps)


    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 2 years, 5 months ago by Kx. Reason: adding clarification
    • This topic was modified 2 years, 5 months ago by Kx.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support ying

    (@yingscarlett)

    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

    (@krisphelps)

    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

    (@yingscarlett)

    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

    (@krisphelps)

    That’s perfectly clear. Thank you.

    Plugin Support ying

    (@yingscarlett)

    You are welcome ??

    Plugin Support fernandoazarcon2

    (@fernandoazarcon2)

    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.