[Resolved] List pages based on tags?
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?
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:
I am almost there but now I want to limit the output to PAGES and exclude posts. I’ve tried the following:
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?
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.
This seems to be a bug in the WordPress code. The post_type parameter gets ignored when you specify a tag parameter.
Try the method illustrated by michael here, it should still apply for a regular loop…
Does the post type then act correctly?
Thank you @randomanic and @t31os_,
I have tried MichaelH’s code, but it still ignores the page type. Here is what I’ve used:
'post_type' => 'page',
'post_status' => 'publish,pending',
$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.
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..
- The topic ‘[Resolved] List pages based on tags?’ is closed to new replies.