Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Content template for loop of CPT grouped by custom taxonomy term

  • Hi!

    A few weeks ago you answered me that in a future GB update, with the query loop, it will be possible to group the posts by taxonomy as in this example here: https://laurenpittenger.com/snippets/loop-cpts-group-custom-taxonomy-terms/

    Is there any estimated date for the implementation of this functionality?

    Until that comes, I have tried to include the snippet of the previous example inside a WordPress page and I have managed to create a loop grouped by custom taxonomy.

    Then I tried to create a content template with GP Premium and GB, but when I publish it, the listing grouped by taxonomy disappears from the page and only the page title is shown.

    Example of the snippet working: https://ibb.co/NZ9hycH
    Example of what happens when activating a GP content template: https://ibb.co/yFvqTHV

    Am I doing something wrong when I apply the content template, or is it that GP elements is not compatible with the snippet that generates the loop grouped by taxonomy?

  • Hi there,

    Is there any estimated date for the implementation of this functionality?

    Do you mean adding CPT to a page?
    If so, you can use the query loop block of GenerateBlocks and select the post type.
    You can have multiple query loop blocks on a page.

    Am I doing something wrong when I apply the content template, or is it that GP elements is not compatible with the snippet that generates the loop grouped by taxonomy?

    It’s not compatible. As content template requires GP’s template while the PHP code creates its own custom template.

  • Hi Ying and thanks for your response

    Is there any estimated date for the implementation of this functionality?

    By this I meant the possibility of creating with the GB query block a list of CPTs grouped by taxonomy, as in the example sent.

    Some time ago, I think Dave commented that it was a functionality that was planned to be added in the future.

  • If you want to use the query loop block on a static page to achieve this, this topic is pretty similar:
    https://generate.support/topic/group-query-loop-per-month-by-post-meta-date-field/

    The code in your case would be something like this, changemy-termto the CSS class you add to the query loop block > grid, change custom_tax to your taxonomy and change custom_tax_term_A to your term.

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
    
        if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-term' ) !== false ) {
    
            $tax_query = array(
                array(
                    'taxonomy' => 'custom_tax',
                    'field'    => 'slug',
                    'terms'    => 'custom_tax_term_A',
                ),
            );
    
            $query_args = array_merge( $query_args, array(
                'tax_query'  => $tax_query,
            ) );
        }
    
        return $query_args;
    }, 10, 2 );
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.