tags:

views:

25

answers:

1

Hello All,

I would like to know the best method for layering posts in wordpress 3.0 when you need to swap back and forth between structure and data. For example, custom post type 1 has 6 custom fields, each field contains a value for the tab shortcode; i.e. [tab:data] [tab:credits] [tab:where to buy] etc - this type is standard every time the page is called and always the same post; then it needs to switch to another custom post type and select the data post it's going to use based on what tag page is being called. Then it needs to pump a custom field from data post into the same display space as the base structure post, and then hop back and forth between structure and data, and THEN run a loop. Thanks in advance.

+1  A: 

I would just query for the two special posts before you do the loop, with get_posts (which will not mess up the regular query). Then you can display them however you want, with their information mixed together, and then do the loop.

In this example, $fixed_post is a fixed post with slug "fixed_post_slug" of the custom post type "fixed_posts". $tag_post is a post where the name equals the current tag (if we are showing a tag page), and of custom post type "tag_posts".

$fixed_post = get_posts(array('name' => 'fixed_post_slug', 'type' => 'fixed_posts'));
if ($fixed_post) {
   $fixed_post = $fixed_post[0]
}
$tag_post = get_posts(array('name' => get_query_var('tag'), 'type' => 'tag_posts'));
if ($tag_post) {
   $tag_post = $tag_post[0];
}
Jan Fabry
Thanks; trying to integrate this crashes on the $home_post = $home_post[0] line for some reason:$home_post = get_posts(array('ID' => '76', 'type' => 'home_content'));if ( $home_post ) { $home_post = $home_post[0];}$today_key = get_post_meta($home_post, 'today');$frontgameswidget_key = get_post_meta($home_post, 'frontgameswidget');$frontwantedwidget_key = get_post_meta($home_post, 'frontwantedwidget');echo $today_key;echo $frontgameswidget_key;echo $frontwantedwidget_key;endif;(don't really know how to format this so I guess copy/paste somewhere)Am I doing something stupid?
What is the contents of `$home_post`? What does `var_dump($home_post)` give you?
Jan Fabry
I figured it out...stupid syntax stuff. thanks for your help!