Site logo

[Resolved] Block Loop Element on Archive Page Only Displays One Item

Home Forums Support [Resolved] Block Loop Element on Archive Page Only Displays One Item

Home Forums Support Block Loop Element on Archive Page Only Displays One Item

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #2587809
    Samuel

    I am sure I am missing something obvious, but I cannot get a custom post type archive to display correctly using a block loop element. I created the block loop element and assigned it to the archives for the custom post type. However, when I visit the custom post type archive page I do not see what I expect. There should be three posts. Instead of seeing three posts I see the first post and it shows up twice.

    This is the first time I’m using this element and I’m sure I’m missing something obvious but I cannot figure out what the problem is.

    #2588002
    Fernando
    Customer Support

    Hi Samuel,

    So we can take a closer look at your setup, can you provide admin login credentials?

    Please use the Private Information field for this: https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information

    #2588022
    Samuel

    Yes, I’ve added the credentials to the private information area.

    #2588040
    Fernando
    Customer Support

    That’s odd. Can you try recreating the Query Loop and enabling “Inherit query from template”?

    #2588068
    Samuel

    I did. And now I just get “no results found.”

    #2588085
    Fernando
    Customer Support

    I see.

    How was this taxonomy/category created?

    #2588572
    Samuel

    It is a custom post type. Created by:

    add_action('init', function () {
    	register_post_type( 'prayer-hub',
    		array(
                'labels' => array(
                    'name'               => __( 'Prayer Hubs', 'isaiah62' ),
                    'singular_name'      => __( 'Prayer Hub', 'isaiah62' ),
                    'menu_name'          => __( 'Prayer Hubs', 'isaiah62' ),
                    'name_admin_bar'     => __( 'Prayer Hubs', 'isaiah62' ),
                    'add_new'            => __( 'Add New', 'isaiah62' ),
                    'add_new_item'       => __( 'Add New Hub', 'isaiah62' ),
                    'new_item'           => __( 'New Hub', 'isaiah62' ),
                    'edit_item'          => __( 'Edit Hub', 'isaiah62' ),
                    'view_item'          => __( 'View Hub', 'isaiah62' ),
                    'all_items'          => __( 'All Prayer Hubs', 'isaiah62' ),
                    'search_items'       => __( 'Search Hubs', 'isaiah62' ),
                    'parent_item_colon'  => __( 'Parent Hub:', 'isaiah62' ),
                    'not_found'          => __( 'No Prayer Hubs found.', 'isaiah62' ),
                    'not_found_in_trash' => __( 'No Prayer Hubs found in Trash.', 'isaiah62' )
                ),
                'public'              => true,
                'has_archive'         => true,
                'description'         => __( 'Prayer Hubs.', 'isaiah62' ),
                'hierarchical'        => false,
                'exclude_from_search' => false,
                'publicly_queryable'  => true,
                'show_ui'             => true,
                'show_in_nav_menus'	  => true,
                'show_in_menu'        => true,
                'show_in_admin_bar'	  => 'true',
                'query_var'           => true,
                'rewrite'             => array( 'slug' => 'prayer-hub' ),
                'show_in_rest'        => true,
                'capability_type'     => 'post',
                'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions', 'page-attributes', 'custom-fields' )
    		)
    	);
    } );
    #2588760
    David
    Staff
    Customer Support

    Hi there,

    can you try rebuilding your permalinks. To do that, go to Dashboard > Settings > Permalinks and click save changes. IF it still doesn’t work, retry that again , and clear any caches.

    Then let us know

    #2588776
    Samuel

    Unfortunately that didn’t change anything. I’m really baffled by this.

    #2589331
    Ying
    Staff
    Customer Support

    Hi Samuel,

    I checked your loop template, and currently, there’s no content inside the post template container block, can you add something inside so I can do another check?
    https://www.screencast.com/t/1tLEIe9lBkdm

    #2589544
    Samuel

    I would but it does not give me any way to add content. The + I would expect to see is not there. How do I add content to the post template container block?

    #2589661
    Ying
    Staff
    Customer Support

    Remove the current one, and re-add a new query loop block, it should come with built-in content.

    #2589721
    Samuel

    Ok now it is working. But it only worked after I set the post type to the custom post type before I set the query block to inherit query from template. I’m still confused on why it wasn’t working but it appears to be working right now. However, I have one question: in order to get some data formatted the way I want to I needed to create a custom shortcode. However, when I run that shortcode functions like get_the_title() on return information for the first post in the loop. On subsequent posts they still return the information for the first post. What is the correct way to access the proper post ID when the query loop is running?

    #2589754
    Fernando
    Customer Support

    Hi Samuel,

    What title are you getting? The title of Posts should be retrievable through a GB Headline Block with no code needed: https://docs.generateblocks.com/article/dynamic-data-options-overview/

    But if you want to use code to add data, you need to use a filter for it. It’s called render_block. Example of its usage: https://generatepress.com/forums/topic/how-to-include-php-within-query-loop-on-homepage/#post-2541974

    #2590386
    Samuel

    In my case, for example, there are a few ACF fields being used to capture data. And, for example, if there is a link in one ACF field the title needs to be a link. If there is not one it’s just a title. The best way I could think of doing that was a shortcode. There is also some content that needs to be optionally shown based on ACF data. A shortcode also seems the best way to do that.

    Is there no way to get the correct post id when a Query Look is running? In the render_block example it is using get_the_ID() so can I not simply use get_the_ID() or get_queried_object_id() to get the correct post information if get_the_title() etc won’t work in a QueryLoop?

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