Archived topic
Custom Post Type: Page hero element is not showing
27 replies · Started by webteam on February 16, 2022
Hi Guys,
Here we are building a site with a CPT called Courses: https://professionaltrainingsolutionscomau.wpstaging.io/courses/
We have a page hero elements added, but it is not displaying in the category pages.
It's using the same Archive.php yet no luck.
Can we please have a look?
Cheers
TCC Web Team.
Hi there,
Upon investigation, I immediately encountered this issue: https://share.getcloudapp.com/OAu4e8dZ
This could be causing the issue. Could you try clearing the Display rules location and placing them again?: https://share.getcloudapp.com/eDulJXbX
If this doesn’t work, can you try setting it to Post Category Archive and see what happens?
Kindly let us know how it goes. Hope to hear from you soon. :)
Hi there,
Thank you for checking this and sorry about the DB issue error. The hosting team checking it while we change the display rules.
We checked it by enabling the blog here as well:
https://professionaltrainingsolutionscomau.wpstaging.io/blog/
No Page Hero here: https://professionaltrainingsolutionscomau.wpstaging.io/category/uncategorized/
It doesn't seem like work. We put login credentials for you to check on the first thread in the private note. Feel free to log in and check if you would.
Kind regards,
Webteam
Thank you for getting back to us.
I can indeed see that no Element is being effectively applied to the Category pages as you mentioned.
The next steps we could do to figure out the cause of this are the following:
1. First, can you try rebuilding your permalink structure? Can you kindly try number 1 in the link?: https://www.hostinger.ph/tutorials/wordpress-broken-permalinks#:~:text=permalinks%20in%20WordPress.-,1.%20Resetting%20Permalinks%20Structure,-The%20simplest%20way
2. Can you also try clearing also caching mechanisms in place in your website?
3. Lastly, can you also try #1 here?: https://docs.generatepress.com/article/debugging-tips/
See this for reference: https://share.getcloudapp.com/JruG982y
Kindly let us know how it goes. Hope to hear from you soon! :)
Hi Fernando,
Thanks for the prompt reply, think we found the culprit.
There was a code chunk in the function.php to enable Custom Post Type Category to use Archive.php
/*function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'nav_menu_item', 'courses'
));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );*/
Now the POST cat is working fine, https://professionaltrainingsolutionscomau.wpstaging.io/category/uncategorized/.
CPT cat page: https://professionaltrainingsolutionscomau.wpstaging.io/category/high-risk-lisence/ use the same Archive but no content.
Any idea on this, please.
Kind regards,
Thank you for getting back to us. I see. You would need that code to make them appear. You just need to modify it for the Elements functionality to work.
Here is a sample PHP you can try:
add_filter( 'generate_elements_custom_args', function( $args ) {
$args['suppress_filters'] = true;
return $args;
} );
function namespace_add_custom_types($query) {
if( ( is_category() || is_tag() ) && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array( 'post', 'courses') );
return $query;
}
}
add_action('pre_get_posts', 'namespace_add_custom_types', 99, 1);
Kindly let us know how this goes. Hope to hear from you soon! :)
Awesome. That works like a charm.
Thanks for that.
On another note, we are using ACF to upload Category images and using the below function to pull the image up.
function get_acf_category_featured_image( $url ) {
$term = get_queried_object();
$background_image = get_field('category_image', $term);
if ( $background_image ) {
$url = $background_image;
}
return $url;
}
add_action('wp', function(){
if(is_archive()){
//echo "hello";
add_filter( 'generate_page_hero_background_image_url', 'get_acf_category_featured_image' );
}
});
Can you please help on the correct hook and what causes this category to not show the fallback image? This cat does not have any listing available though.
https://professionaltrainingsolutionscomau.wpstaging.io/category/mining-courses/
Kind regards,
An easier way to do this is by setting the Dynamic Background Image you currently have to “Term meta”, and set the Meta field name to the one you set in ACF.
See this for reference: https://share.getcloudapp.com/bLux9qZZ
Hope this helps!
Do you mean to set up another element for Archives with Term Meta?
It seems partially work. https://professionaltrainingsolutionscomau.wpstaging.io/category/safety/
This doesn't show the fallback image. What would be the "Meta field name" to pull cat description on here too?
Cheers
Hi there,
if you want to display different dynamic content then yes you would need to create a separate element for them.
For the category description you would use GP Dynamic Content block, it includes the Term Description:
https://docs.generatepress.com/article/dynamic-blocks/#dynamic-content
Hi David,
Thanks for that.
One last thing:
- if a category is empty but has a category image (e.g: https://professionaltrainingsolutionscomau.wpstaging.io/category/mining-courses/)
- if a category is empty and no category image (e.g: https://professionaltrainingsolutionscomau.wpstaging.io/category/safety/)
No fallback or category image showing in the page hero?
As Fernando, suggested, we used "Term Meta" on the Element, https://share.getcloudapp.com/bLux9qZZ
Kind regards,
How is the background image being stored in ACF? Is it using the image ID ?
Hi David,
It is stored as "Image Array".
Hi @webteam,
On the ACF settings for the background image, can you check the return format?
Image fields usually have 3 options as shown here -
https://share.getcloudapp.com/JruGJDRQ
It should be set to "Image URL". :)
Hi Elvin,
Thanks and it is set to "image URL" now and also tried following up on a prev thread of yours: https://share.getcloudapp.com/BluK6JJd
But still cannot get the fallback image or the uploaded image into the empty category. and this happens only for the empty category.