How to use the count command?

Hi all!

I’m currently using this little snippet to show how many posts there are with a specified tag

$term = get_term_by('slug', lizard, post_tag);
// Fetch the count
echo $term->count;

My mission is to count several different tags and add them together.
But I don’t really understand the echo $term->count; function.

Is there anyway to instead of echoing the answer, to store it in a variable?, For example $lizzard?

$term is a wordpress WP_Term object; count is one of its properties.

echo is just a php statement meaning “print what I give you to the output”. The function print() has more or less the same effect.

If you want to assign a value (such as an object property) to a variable, you can use $variable_name = expression; so in this example, $lizzard = $term->count;.

This information was exactly what I needed, thx for the information!

Sponsor our Newsletter | Privacy Policy | Terms of Service