- This topic is empty.
-
AuthorPosts
-
February 7, 2013 at 1:38 am #42540
sanclementejoe
ParticipantI have a custom taxonomy called stores, so I can’t use the code for a standard category as defined here http://codex.wordpress.org/Function_Reference/get_the_category
So I took a look at http://codex.wordpress.org/Function_Reference/get_term_by but can’t figure what I need to do.
This is my code
$value = get_field(‘extended_store_descriptions’, ‘stores_’ . $cat_id );
echo $value;
?>All I need to do is make that number 47 dynamic instead of static and I’ve tried this:
$cat_id = get_query_var(‘stores’);
$value = get_field(‘extended_store_descriptions’, ‘stores_’ . $cat_id );
echo $value;?>
But that didn’t work. I don’t know if I should be using this:
[http://codex.wordpress.org/Function_Reference/wp_get_post_terms](http://codex.wordpress.org/Function_Reference/wp_get_post_terms “”)
or this
[http://codex.wordpress.org/Function_Reference/get_terms](http://codex.wordpress.org/Function_Reference/get_terms “”)
Thanks so much!
February 7, 2013 at 9:02 pm #123752sanclementejoe
ParticipantHopefully some kind soul with the chops can help me out:
When I do this:
$terms = get_the_terms($post->ID, ‘stores’);
print_r($terms);
?>It gets me close to what I want:
This is outputted:
_Array ( [47] => stdClass Object ( [term_id] => 47 [name] => Amazon.com [slug] => amazon-com [term_group] => 0 [term_taxonomy_id] => 49 [taxonomy] => stores [description] =>
Amazon Coupon Codes
Amazon is the world’s largest online retailer. The company also produces consumer electronics, and is a major provider of cloud computing services. [parent] => 0 [count] => 1 [object_id] => 40 ) )_But I only want the number 47 in there
February 7, 2013 at 9:03 pm #123753TylerNYC
Member$terms
February 7, 2013 at 9:43 pm #123756sanclementejoe
ParticipantI figured it out with some help from this page: [http://wordpress.org/support/topic/trying-to-output-a-posts-terms-taxonomy-as-text-not-urls#post-1188801](http://wordpress.org/support/topic/trying-to-output-a-posts-terms-taxonomy-as-text-not-urls#post-1188801 “”)
// Get terms for post
$terms = get_the_terms( $post->ID , ‘stores’ );// Loop over each item since it’s an array
foreach( $terms as $term ) {
// Print the term_id method from $term which is an OBJECT
// $lovers will be grabs the current store page id
$lovers= $term->term_id;
// Get rid of the other data stored in the object, since it’s not needed
unset($term);
}
?>$cat_id = $lovers;
$value = get_field(‘extended_store_descriptions’, ‘stores_’ . $cat_id );
echo $value;?>
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.