Site logo

[Resolved] Change post per page – custom post type archive page. Element templates skipped

Home Forums Support [Resolved] Change post per page – custom post type archive page. Element templates skipped

Home Forums Support Change post per page – custom post type archive page. Element templates skipped

Viewing 15 posts - 16 through 30 (of 35 total)
  • Author
    Posts
  • #2117317
    Elvin
    Staff
    Customer Support
    #2117329
    Brad

    Thanks. Yeah. Same related issue. The GenerateBlocks Elements Content Template layouts get bypassed for some reason when I’ve added a couple different functions to change things.

    1.
    Post per page for CPT

    2.
    Add CPT to categories

    #2117342
    Elvin
    Staff
    Customer Support

    Strange,

    I’ve just tested this as well on this test category –
    http://elvin.wppluginsupport.net/category/test

    You can inspect the page and see that some posts now have type-showcase indicating showcase CPT while the content template is intact:
    https://share.getcloudapp.com/mXuJ49AY

    For reference, the setup of the sandbox site is basically:

    – WordPress 5.9
    – Latest versions of GP Premium and GeneratePress
    – No child theme or other plugins active. (Only GenerateBlocks and CPT UI active)

    If you can replicate this setup and see it working for the purpose of having a known working control version, we can work our way through the plugins. (Enabling 1 by 1 to see which is the issue.)

    If it’s not the plugins, we can try re-saving permalinks and then go through the child theme.

    #2118320
    Brad

    Ok. I really didn’t want to go to Wp 5.9 but I went ahead and did it (I’ve got a backup).

    SITE
    www . stagingblocks-01.j66labs. co
    Parent GP theme active
    All plugins deactivated except GP Pro and GB Pro
    All snippets turned off

    Pagination issue: fixed
    The problem was a plug-in for custom permalinks for CPT.

    Main issues (gb elements content template layout disappearing once adding scrips) were still present. I deactivate in a somewhat logical order, although turned scrips off first. Probably should of left them on, turn them off last.

    #2118868
    Elvin
    Staff
    Customer Support

    Main issues (gb elements content template layout disappearing once adding scrips) were still present. I deactivate in a somewhat logical order, although turned scrips off first. Probably should of left them on, turn them off last.

    With this, the procedure for debugging is disabling ALL Block elements and enable them one by one and see if a one’s display rule location conflicts with another.

    I see you had almost 2 pages worth of elements. It may be worth checking if some of them have overlapping display rules. 😀

    #2118875
    Brad

    Ok. I didn’t realize that was an option. I’ll try that next. First though I need to reactivate bare minimum plugins, CPT UI and ACF Pro plug-ins though, yes to populate posts?

    #2118887
    Elvin
    Staff
    Customer Support

    CPT UI and ACF Pro plug-ins though, yes to populate posts?

    That’s right. Actually, you must keep them on for this.

    Else, you probably won’t be able to test the archives as CPT UI generates it when you made the CPT.

    #2119117
    Brad

    Quick lame question. How do you turn off element? Put them in draft mode, throw in trash then restore?

    #2119124
    Elvin
    Staff
    Customer Support

    Quick lame question. How do you turn off element? Put them in draft mode, throw in trash then restore?

    Putting it to “Draft” will do.

    #2123336
    Brad

    Ok. Went through as suggested on staging block-01 site. Strange. Header came back on “photography” category but that’s it. Now I have bare minimum elements running with required plugins for site to work. Same issues though.

    Something is conflicting to not allow GenerateBlocks Elements to show once the “post limit per cpt” script is add as well as the “add category support to cpt”.

    Any suggestions from here?

    #2123605
    Elvin
    Staff
    Customer Support

    I see you have multiple pre_get_posts snippets on your site. https://share.getcloudapp.com/12u0YA2n

    We should maintain just 1 and do all the conditions on that 1 pre_get_post filter so it’s easier to follow.

    I did some edits on the code and the “— Limit Post Per Page — CPT photography — 220213″ snippet and you can see that it works now.

    I basically merged the conditions of this one and CPT showcase as well so you only have to maintain 1 for both but I suggest doing the same for the snippet ” — Show cpt in categories — ” as it’s redundant.

    See it working here – https://share.getcloudapp.com/yAukNDdr

    You can see that it now displays 3 posts per page WHILE maintaining the block element content template. 🙂

    #2123655
    Brad

    Sincere thank you!!!!

    Ok. Interesting and strange. I think function number 1 purple in my screenshot adds support to include CPT in categories by default.

    I had a function to add this. Possibly that was screwing everything up plus I had the purple number 1 filter listed three times.

    https://www.dropbox.com/s/2e7ol6rkqk6lk5y/Post-per-page.jpg?dl=0

    Now I have the following with no function to add category support to CPT.

    add_filter( ‘generate_elements_custom_args’, function( $args ) {

    $args[‘suppress_filters’] = true;

    return $args;
    } );

    function j66co_photography_posts_per_page($query) {
    if ( is_post_type_archive( ‘photography’ ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set(‘posts_per_page’, 3);
    }

    if( ( is_category() || is_tag() ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set( ‘post_type’, array( ‘post’,’photography’) );

    return $query;
    }
    }
    add_action(‘pre_get_posts’, ‘j66co_photography_posts_per_page’, 99, 1);

    function j66co_showcase_posts_per_page($query) {
    if ( is_post_type_archive( ‘showcase’ ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set(‘posts_per_page’, 4);
    }

    if( ( is_category() || is_tag() ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set( ‘post_type’, array( ‘post’,’showcase’) );

    return $query;
    }
    }
    add_action(‘pre_get_posts’, ‘j66co_showcase_posts_per_page’, 99, 1);

    #2123663
    Elvin
    Staff
    Customer Support

    No need to put them in separate add_action(). We can do with just one.

    Example:

    function j66co_photography_posts_per_page($query) {
    
        /* assign post_per_page to archives with Block Element - Content Template */
        if ( empty( $query->query_vars['suppress_filters'] ) ) {
            
            if( is_post_type_archive( 'photography' ) ){
                /* PPP 3 for Photography */
                $query->set('posts_per_page', 3);
            } elseif ( is_post_type_archive( 'showcase' )  ){
                /* PPP 3 for Showcase */
                $query->set('posts_per_page', 4);
            }
        }
    
        /* Add CPTs to category and tag archives */
    	if( ( is_category() || is_tag() ) && empty( $query->query_vars['suppress_filters'] )  ) {
    		 $query->set( 'post_type', array( 'post', 'photography', 'showcase') ); 
    		return $query;
    	}
    }
    add_action('pre_get_posts', 'j66co_photography_posts_per_page', 99, 1);

    The array in $query->set( 'post_type', array( 'post', 'photography', 'showcase') ); lets you add in more CPT to the cat or tag archive.

    #2123710
    Brad

    Yeah IDK why but the more efficient code doesn’t work.

    IDK what’s going on. Here’s a link to the main dev site working know with just my inefficient code below:

    https://blocks-01.j66labs.co/showcase/

    add_filter( ‘generate_elements_custom_args’, function( $args ) {

    $args[‘suppress_filters’] = true;

    return $args;
    } );

    function j66co_photography_posts_per_page($query) {
    if ( is_post_type_archive( ‘photography’ ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set(‘posts_per_page’, 3);
    }

    if( ( is_category() || is_tag() ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set( ‘post_type’, array( ‘post’,’photography’) );

    return $query;
    }
    }
    add_action(‘pre_get_posts’, ‘j66co_photography_posts_per_page’, 99, 1);

    function j66co_showcase_posts_per_page($query) {
    if ( is_post_type_archive( ‘showcase’ ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set(‘posts_per_page’, 4);
    }

    if( ( is_category() || is_tag() ) && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set( ‘post_type’, array( ‘post’,’showcase’) );

    return $query;
    }
    }
    add_action(‘pre_get_posts’, ‘j66co_showcase_posts_per_page’, 99, 1);

    #2123727
    Elvin
    Staff
    Customer Support

    This URL is not a category page. It’s an archive specifically for the CPT Showcase so only cpt with name of showcase will display here.

    Can you link us to a category page w/ the supposed mix of cpts?

Viewing 15 posts - 16 through 30 (of 35 total)
  • You must be logged in to reply to this topic.