Using get_tags() to query the tag containing meta_key from the tag has no result

[ad_1]

Hi @bob19852022
It looks like you are trying to set metadata for tags in WordPress and then retrieve the tags sorted by the metadata value using the get_tags() function. There are a couple of things you can try to troubleshoot this issue:

1. Make sure you use the correct syntax for the orderby parameter in the get_tags() function. The correct syntax is 'orderby' => 'meta_value_num'.

2. Make sure you have correctly set the metadata for the tags. You can check if the metadata has been set correctly by using the get_post_meta() function to retrieve the metadata for a specific tag.

3. Make sure that you are using the correct key for the metadata. In your code, you are using $metakey as the key for the metadata, but in the get_tags() function, you are using 'tcode' as the key. Make sure that these keys match.

4. Make sure you use the correct tag ID when calling the get_tags() function. You can use the get_term_by() function to retrieve the tag ID based on the tag name or slug.

5. Make sure you have at least one tag with the metadata key and value you are trying to retrieve. The get_tags() function will return an empty array if no tags match the specified criteria.

I hope this helps! If you are still having issues, please provide more information about the specific error messages or issues you are experiencing, and I will do my best to help.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer