Site logo

Archived topic

Get Terms CPT does not work with Elements

1 reply · Started by FunkyCss on October 22, 2021

Viewing posts 1–2 of 2

Hi there,

I have created a CPT product_categories and I try to hook the query ,

The hook works just fine, <?php do_action( 'generate_before_main_content' ); ?>

My issue is that the PHP inside does not work. ( I have enabled the php in the hook )

My code

	<?php
				$terms = wp_get_post_terms( $post->ID, 'product_category');
					foreach ( $terms as $term ) {
					$term_link = get_term_link( $term );
					echo '<div class="product-category"> <a class="solo-category" href="' . $term_link . '">' . $term->name . '</a></div>' . ' ';
				}
				?>

Take notice , if paste this code inside the custom template it works just fine but with Elements will show nothing.

Hi there,

try adding: global $post; at the top of your code.

This archived topic is closed to new replies.