I have some option in some of my wordpress tags and I'm trying to determine (in single.php
) if one of those tags has options and if one of them (options) is equal to a specific value.
This is what I got so far but I'm a bit lost on how to move forward:
// get all post tags
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
// get the tags ID
$tag_id = $tag->term_id;
// putt all the ID's on an array
$all_tags_id = array($tag_id . ', ');
... and I don't know how to go any further from here.
I guess I first need to isolate the ones that have options and then see if any of them has the option that I need empty
OR not?
Help needed...
I have some option in some of my wordpress tags and I'm trying to determine (in single.php
) if one of those tags has options and if one of them (options) is equal to a specific value.
This is what I got so far but I'm a bit lost on how to move forward:
// get all post tags
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
// get the tags ID
$tag_id = $tag->term_id;
// putt all the ID's on an array
$all_tags_id = array($tag_id . ', ');
... and I don't know how to go any further from here.
I guess I first need to isolate the ones that have options and then see if any of them has the option that I need empty
OR not?
Help needed...
Share Improve this question edited Oct 11, 2020 at 1:30 Tom J Nowell♦ 61k7 gold badges79 silver badges148 bronze badges asked Oct 10, 2020 at 12:51 bpybpy 2995 silver badges20 bronze badges 3 |1 Answer
Reset to default 1If you have a term, you can retrieve its meta via get_term_meta
, this function works the same way as get_post_meta
only it takes a term ID not a post ID
E.g.
if ( get_term_meta( $term_id, 'key', true ) === 'value' ) {
// it has the value
}
Once you know this, it's just basic logic of looping over each term and checking them, which you already do in the code in your question
tags
have specific options. See this here to understand. – bpy Commented Oct 10, 2020 at 13:05