Forums

List pages based on tags? (7 posts)

  1. betadog
    Member
    Posted 7 months ago #

    I would like to list all pages that contain a certain custom field value. I am no PHP hack but I've come up with the following code snippet:

    <?php wp_list_pages('meta_key=tags&meta_value=blue'); ?>

    This works fine, it lists all pages that have EXACTLY the value "blue" in the custom field "tags". But how can I modify the snippet to list all pages that CONTAIN the value "blue"? That way I could assign multiple tags (e.g. "blue, big, tasty") to one page.

    Or is there any better way to list pages based on tags?

  2. betadog
    Member
    Posted 5 months ago #

    Okay, I am back at it and I found a plugin called "Page-Tags" which allows me to assign tags to pages. Great.

    I've looked at query_posts and lo and behold, it allows me to list everything with that tag, including the pages I've tagged with the above mentioned plugin. Awesome.

    The query I've put before the loop is as follows:

    query_posts('tag=blue&orderby=title&order=ASC');

    I am almost there but now I want to limit the output to PAGES and exclude posts. I've tried the following:

    query_posts('tag=blue&post_type=page&orderby=title&order=ASC');

    But it still lists pages AND posts, apparently the 'post_type=page' is ignored.

    I am way out of my depth here, can anybody help me? Again: is there a better way to list pages based on tags? Will there be a better way in WP 2.8? Will Wordpress ever include a decent tagging feature for pages?

  3. randomaniac
    Member
    Posted 4 months ago #

    Hey, I've had a go at doing what you mentioned using the same plugin and I'm also seeing this issue, i.e. it seems to ignore the post_type option you pass in.

  4. randomaniac
    Member
    Posted 4 months ago #

    This seems to be a bug in the Wordpress code. The post_type parameter gets ignored when you specify a tag parameter.

  5. t31os_
    Member
    Posted 4 months ago #

    Try the method illustrated by michael here, it should still apply for a regular loop...

    http://wordpress.org/support/topic/285939?replies=7#post-1123971

    Does the post type then act correctly?

  6. betadog
    Member
    Posted 4 months ago #

    Thank you @randomanic and @t31os_,

    I have tried MichaelH's code, but it still ignores the page type. Here is what I've used:

    <?php
    $params=array(
    'showposts'=>5,
    'post_type' => 'page',
    'post_status' => 'publish,pending',
    'tag'=>'blue'
    );
    $query = new WP_Query;
    $results = $query->query($params); ?>

    It does not matter whether I set the post_type to page, post or any. It always gives me any post or page.

  7. t31os_
    Member
    Posted 4 months ago #

    That's because the plugin you mentioned before sets post_type to any, see the plugin code (it's only a single file, very little code), and you'll find a line that refers to the post_type..

    That would be my guess anyway... assuming you're still using the plugin..

Reply

You must log in to post.

About this Topic