WordPress.org

Ready to get started?Download WordPress

Forums

Show posts from 1 category AND tag matches custom post title (2 posts)

  1. plinth
    Member
    Posted 2 years ago #

    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...

  2. vtxyzzy
    Member
    Posted 2 years ago #

    I suspect that the problem is that the 'tag=' parameter uses the tag slug, while the title is probably capitalized and may contain spaces or special characters.

    Here are a couple of links to articles that describe how to get the slug for a post. You can probably use part of the code in your application.


    http://www.insitewebsitedesign.com/wordpress-post-slug-and-page-slug-function

    http://www.wenderhost.com/2007/08/wordpress-tip-find-the-current-page-slug/

Topic Closed

This topic has been closed to new replies.

About this Topic