WordPress.org

Support

Support » How-To and Troubleshooting » Show posts from 1 category AND tag matches custom post title

Show posts from 1 category AND tag matches custom post title

  • Yes I’ve searched, yes I’ve tested, but still no joy. What I’m trying to do is this:

    I have a custom post type (client), a category (press-office) and a bunch of tags which match the client names.

    When viewing a client page (single-client.php) I’ve already set it to show information entered in specific custom fields. But what I want at the bottom of this page is a list of all posts added to the ‘press-office’ category where the tag matches the client name (added as the post title).

    So in real-world terms, I add a new client as a custom post type and enter “Nike” as the title. Then I add a new post in the “Press Office” category and also a tag of “Nike”. This post then appears at the bottom of the Nike client page.

    What I’ve ended up with is this:

    <?php
    global $post;
    $tag = get_the_title();
    query_posts(array('category_name' => 'press-office', 'tag=' . $tag . ''));
    if ( have_posts() ) while ( have_posts() ) : the_post();
    echo '<li>';
    the_title();
    echo '</li>';
    endwhile;?>

    But that just echoes everything from the press office category. Over to you…

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Show posts from 1 category AND tag matches custom post title’ is closed to new replies.
Skip to toolbar