Forums

[resolved] $post variable in a tag archive (UTW) (7 posts)

  1. sevennine
    Member
    Posted 3 years ago #

    I'm using Ultimate Tag Warrior plugin (or at least trying to) and I've got it displaying posts in a certain tag, the questions I ask are:

    1) I'm haivng trouble calling the $post variable in THE LOOP, as int print_r($post) doesn't print out anything, shouldn't it printout the $post's variables?

    2) is it possible to us the "query_posts" function call and call posts that containt certain tags?

  2. Kafkaesqui
    Moderator
    Posted 3 years ago #

    1) If this is in a plugin, are you scoping $post to global, as in:

    global $post;

    This would (naturally) occur before making use of $post in your code.

    2) Tags are not considered a built-in WP component which relates to the posts table, so it would be difficult (if not impossible) to make use of query_posts for something like this.

  3. NoelCower
    Member
    Posted 3 years ago #

    You wouldn't be able to use query_posts, but you could do something like this to get the IDs of posts with certain tags:

    global $tablepost2tag;
    $wpdb->get_results( "SELECT post_id FROM $tablepost2tag WHERE tag_id = $tag" );

    It's not much, since I've not had to do anything like #2, but it should get you started.

  4. sevennine
    Member
    Posted 3 years ago #

    you would think that wouldn't you? but the following only produces a list of the titles, am I missing something here? Shouldn't it produce the title and the post's details?

    <?php
    if (have_posts()) :
    while (have_posts()) : the_post();
    the_title();
    print_r($post);
    endwhile;
    endif;
    ?>

  5. Kafkaesqui
    Moderator
    Posted 3 years ago #

    Question is, where do you have this code running? It works (as expected) when I dump it into my theme's index.php.

  6. sevennine
    Member
    Posted 3 years ago #

    its running in TAG.PHP and is called when the tag archive is called for the Ultimate Tag Warrior plugin

  7. sevennine
    Member
    Posted 3 years ago #

    got some reason $post wasn't globally called, just added
    global $post;
    and it was all good

Topic Closed

This topic has been closed to new replies.

About this Topic