Archived topic
Block Element not working for CPT Archive
16 replies · Started by Elías Gómez on August 7, 2021
Hello!
I have a Custom Post Type, and I have created a Block Element of Content Template type for using in the Archive. If I set it to blog it works, but if I set it to "Idea Archive" (idea is my CPT), it does not work. If I set to "All Archives" or "Entire Site" it neither work.
In the Elements item of the Admin Bar it appears as working, but it does not work. I leave screenshots: https://imgur.com/a/zTV5Cr8
I've made all type of test: disabling all plugins, disabling other elements, installing a plugin that generated CPTs...
What's happening? Can you help me?
Thanks!
Hi there,
did you create a Custom Template for the CPT Archive ?
No, I'm using the built in archive.php. Also, I'm using a child theme. These are the files that are loading:
https://i.imgur.com/FSzOWD5.png
Do the CPTs display if you DO NOT use a Block Element ?
Yes, you can see in the link of my first message (those black rectangles are the title, there is no content because it dummy content hehe).
Can you try to disable all plugins except GP Premium and switch back to the parent theme to test?
Let me know :)
I already tried that...
That's weird, can you keep all plugins deactivated except GP premium and switch to the parent theme.
You can use the private info field to share the admin access to your site, we can have a look at the backend. :)
I leave a video and credentials on the private area.
Thanks!
Can you try to remove the changes that you did to the ACF plugin to test?
What do you mean? I just created a couple of forms with ACF, but the plugin is deactivated.
The Block Element Content Template uses the generate_do_template_part function:
If the conditions are met it replaces the content template with the Block Element.
Looking at your CPT setup you're relying on the default content template, that is being filtered and hooked into.
Which means the template has nothing to output....
If in the Block Element, you try setting one of the 'headlines' to Dynamic Text Type > Post Meta and add your Custom Field name - do you see that on the front end?
Hello.
I don't understand what do you mean, why that function has nothing to output?
I neither know what custom field are you talking about, I have none nor talked about any 🤔
Anyway, the Helpful plugin I'm using set the votes as meta, I set the headline to the helpful-pro meta key and nothing happens.
☹
The function i showed here:
https://github.com/tomusborne/generatepress/blob/2c7c8a76d3b58b0b97e82b3a7a5ebf022a1ddfbe/archive.php#L40
Is what calls the content template.
The Block Element Content Template overwrites that.
You populate the Block Element Content Template with the template tags and post meta you want it to display.
Looking at your Ideas HTML i see this:
https://www.screencast.com/t/LJi9mih5
Which i assume is being generated by a plugin.
And if look at your: votaciones-comunidad.php there are a bunch of action hooks and filters pulling in fields and shortcodes from ACF.
Which to be honest i don't understand what it is doing.... and is really difficult to explain what to change.
The simple setup is:
a Custom Post Type, that has Custom Fields applied to it.
Any Custom Fields attached to a post can then be called in the Block Element > Dynamic Text Type > Post Meta.
If however the 'meta' is being stored elsewhere and is being currently displayed using a Shortcode, then you can add the Shortcode inside a Head line block.
I don't know how all you said is related with the fact that the Block Element is not working.
Is what calls the content template.
The Block Element Content Template overwrites that.
You populate the Block Element Content Template with the template tags and post meta you want it to display.
Yes I know, but why is it not working?
The Helpful plugin allows users to vote the Ideas, and I made a function to output the yes/no buttons (with the [helpful] shortcode). The code of your screenshot is just the result of that. But anyway, I also tested it with this plugin (and all the rest), deactivated. And it didn't worked.
And if look at your: votaciones-comunidad.php there are a bunch of action hooks and filters pulling in fields and shortcodes from ACF.
The ACF part is for the page where the users can send new ideas, as ACF allows to generate forms in the frontend (look at the is_page() conditional on every function). But that, again, has nothing to do with the Ideas Archive.
Anyway, I also tested disabling the whole plugin votaciones-comunidad.php and creating the CPT in the functions.php file, but it didn't work.
Any Custom Fields attached to a post can then be called in the Block Element > Dynamic Text Type > Post Meta.
I tried to show the votes from the Helpful plugin with a Headline but it didn't work.
🤷♂️