Displaying Custom Fields data by Category
-
Hi,
Can anyone help me display a list of blog posts by category along with custom field data. Basically each post on my blog has a custom field which is either “Plus” or “Negative” and I want to display this information alongside the post name sorted by category. For example:
Category One
PostOne “Plus”
PostTwo “Minus”Category Two
PostThree “Plus”
PostFour “Plus”So far I have come up with the following code on a custom page:
<?php $catList = new WP_Query(); $catList->query('year=$current_year'); while ($catList->have_posts()) : $catList->the_post(); ?> <!-- LOOP STUFF HERE --> <ul> <?php global $customFields; $customFields = "'Plus', 'Minus'"; //Comma seperated 's1', 's2', 's3' $customPosts = new WP_Query(); add_filter('posts_join', 'get_custom_field_posts_join'); add_filter('posts_groupby', 'get_custom_field_posts_group'); $customPosts->query('showposts=25' );//Uses same parameters as query_posts remove_filter('posts_join', 'get_custom_field_posts_join'); remove_filter('posts_groupby', 'get_custom_field_posts_group'); while ($customPosts->have_posts()) : $customPosts->the_post(); $plus = get_post_custom_values("Plus"); $minus = get_post_custom_values("Minus"); ?> <li> <?php echo $plus[0]; ?> <?php if ($minus[0]){ ?> -<?php echo $minus[0]; ?> <?php } // this ends the IF ?> <a href="<?php the_permalink() ?>" rel="bookmark"> <?php the_title(); ?></a> (<?php the_time('F Y'); ?>) </li> <?php endwhile; ?> </ul> <?php /* End Custom Field Posts */ ?> </li> </ul> <?php the_category(',') ?> <?php endwhile; ?>
- The topic ‘Displaying Custom Fields data by Category’ is closed to new replies.