-
David
the
has-category-imagegoes on the Container Block where the fallback image is set.If it still don’t work add back the:
var_dump($term); var_dump($image);Into the function after:
$term_id = $queried_object->term_id; -
danstramer
I’m getting Null for both.
on a ‘regular’ category page and also on a CPT category page -
David
Hmmm…
can you add this snippet to your site:add_action('generate_before_header', function(){ $queried_object = get_queried_object(); $term_id = $queried_object->term_id; if ( $term_id) { echo 'Term Id: ' . $term_id; } });It should simply display the Term ID of the current object at the top of the page.
Does that show anything in any tax archive ? -
danstramer
Hi David, added, but nothing is showing up
-
David
Does it do anything on a normal Category Archive ?
-
danstramer
no, nothing
-
David
Hmmm… and if you do this:
add_action('generate_before_header', function(){ $queried_object = get_queried_object(); $term_id = $queried_object->term_id; echo 'Term Id: ' . $term_id; }); -
danstramer
it just adds “Term ID:” before the header
http://pointerisradev.wpengine.com/case_studies/
http://pointerisradev.wpengine.com/blog/ -
danstramer
David, is there a page where we can see all of generateblock’s filters? similar to:
generateblocks_background_image_url -
David
Is there a normal category page ? the Blog doesn’t count, as we’re looking for a tax term ID.
-
danstramer
yes, this is a category page: https://pointerisradev.wpengine.com/category/%d7%97%d7%93%d7%a9%d7%95%d7%aa-%d7%95%d7%a2%d7%93%d7%9b%d7%95%d7%a0%d7%99%d7%9d/
I can see the term id: 13
the image is updating, and so is the description, great!
now, how can we apply this to the main blog page and also to CPT archive page – http://pointerisradev.wpengine.com/case_studies/Dan
-
David
Ok, so thats a step in the right direction,
For the blog, you will need to create a static hero specifically for that.Now the question is why doesn’t the custom taxonomy display a term_id ?
How is that taxonomy set up ? -
danstramer
ok, for the CPT, there is a taxonomy that will display the header image and description:
https://pointerisradev.wpengine.com/case_study_category/case-study/
you can see the container image.
But – the page I would like to show isn’t the CPT category page, but the CPT archive page. Does that make sense? -
David
Aah. I think i missed that it was the archive template and not a tax. And i should have spotted it in the var_dump.
So where would this custom field be stored ? I am not familiar with adding ACF fields to a template.
-
danstramer
see here:
https://support.advancedcustomfields.com/forums/topic/add-image-field-to-cpt-archive/I can add an ACF options page to insert the image, title and description to the CPT archive.
Question is, how do I call it in with a GB page header/block element.Dan
-
David
OK, so if you’re using an options page, then you need a different function as the get_field change, see here:
https://www.advancedcustomfields.com/resources/get-values-from-an-options-page/
For example:
add_filter( 'generateblocks_background_image_url', function( $url,$attributes) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'has-option-image' ) !== false ) { // get the term and the term meta containing the image URL $image = get_field('field_name', 'option'); if ( $image ) { // return the $image return $image; } } return $url; }, 10, 2 );here we use a CSS Class of:
has-option-imageto find the container.
Add here:$image = get_field('field_name', 'option');you would define the field name and the option name.
- You must be logged in to reply to this topic.