Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 612 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wordpress - Get tag id by slug

#1
I am trying to get id\name of tag by it slug.

Thats my code:

$tag = get_term_by('slug', 'hedoms', 'post_tag');
$tag_id = $tag->term_id;

<h1><?php echo $tag->name;?></h1>

I took it from here:
[

[To see links please register here]

][1]

I have tag with the slug **hedoms** but the `<h1>` is empty, it not returns the value. I have tried this function (get_term_by) with category - and same result.

[![enter image description here][2]][2]

the 2nd field is the slug.


But if i do it with id and not slug, it works fine:

$tag_id = get_term_by('id', 97, 'post_tag');
echo $tag_id->name;


It look like the get_term_by recognize only 'id' as field.


What i miss here? it should be on loop or something ?

The file i trying to do it is `archive-product.php` of Woocommerce.


[1]:

[To see links please register here]

[2]:
Reply

#2
$tag = get_term_by('slug', ' hedoms','post_tag');

$tag_id = $tag->term_id;
Reply

#3
OK i have found the solution.

I set on the get_term_by the taxonomy 'post_tag' instead 'product_tag' as it woocommerce tags. Next time i will look carefully on the url of the wp-admin when i am looking on taxonomy page:

...wp-admin/edit-tags.php?taxonomy=product_tag&post_type=product

So the code should be like that:

$tag = get_term_by('slug', $slug, 'product_tag');
$tag_name = $tag->name;

<h1><?php echo $tag_name; ?></h1>


Solved.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through