- This topic has 19 replies, 4 voices, and was last updated 2 years, 11 months ago by
Ying.
-
AuthorPosts
-
March 29, 2023 at 1:42 pm #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.
March 29, 2023 at 6:07 pm #2588002Fernando 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
March 29, 2023 at 6:49 pm #2588022Samuel
Yes, I’ve added the credentials to the private information area.
March 29, 2023 at 7:21 pm #2588040Fernando Customer Support
That’s odd. Can you try recreating the Query Loop and enabling “Inherit query from template”?
March 29, 2023 at 8:27 pm #2588068Samuel
I did. And now I just get “no results found.”
March 29, 2023 at 9:13 pm #2588085Fernando Customer Support
I see.
How was this taxonomy/category created?
March 30, 2023 at 4:27 am #2588572Samuel
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' ) ) ); } );March 30, 2023 at 7:04 am #2588760David
StaffCustomer SupportHi 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
March 30, 2023 at 7:15 am #2588776Samuel
Unfortunately that didn’t change anything. I’m really baffled by this.
March 30, 2023 at 11:15 am #2589331Ying
StaffCustomer SupportHi 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/1tLEIe9lBkdmMarch 30, 2023 at 2:21 pm #2589544Samuel
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?
March 30, 2023 at 5:21 pm #2589661Ying
StaffCustomer SupportRemove the current one, and re-add a new query loop block, it should come with built-in content.
March 30, 2023 at 6:42 pm #2589721Samuel
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?
March 30, 2023 at 7:11 pm #2589754Fernando 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-2541974March 31, 2023 at 4:11 am #2590386Samuel
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?
-
AuthorPosts
- You must be logged in to reply to this topic.