Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter downfast

    (@downfast)

    Thanks but I know how to find an ID, what I am asking is:

    If i give a tag to a post, how can I find this post id by querying its tag?

    You can’t find one specific post but you can find all posts using a specific tag using WP_Query().

    Thread Starter downfast

    (@downfast)

    Ok how do I find the categories of this posts?

    Basically I am using the plugin: https://www.ads-software.com/plugins/user-submitted-posts/

    In the form you can insert a tag; this tag is attached to a post.

    I am using the following and it works but if i duplicate the code below and I change the cat id in order to have all the tags within various categopries where the tags are used, it repeats the same tags for all categories.

    <?php
    		$cat=5;
    		$yourcat = get_category($cat);
    		if ($yourcat) {
    			echo '<h3>' . $yourcat->name . '</h3>';
    		}
    		$args = array(
    			'categories'=> '5'
    		);
    		$tags = get_category_tags($args);
    		$content .= "<ul>";
    		foreach ($tags as $tag) {
    			$content .= "<li><a href=\"$tag->tag_link\">$tag->tag_name</a></li>";
    		}
    		$content .= "</ul>";
    		echo $content;
    	?>
    Thread Starter downfast

    (@downfast)

    Solution:

    <ul>
                    <?php
                        query_posts('category_name=Ambiente');
                        if (have_posts()) : while (have_posts()) : the_post();
                            if( get_the_tag_list() ){
                                echo $posttags = get_the_tag_list('<li>','</li><li>','</li>');
                            }
                        endwhile; endif;
                        wp_reset_query();
                    ?>
    </ul>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Find post id by a tag’ is closed to new replies.