Create list of posts showing post meta and title – ordered by meta asc
-
Hi there.
I’ve been trying to work out how to do this to no avail mainly as I am having trouble understanding the following two support posts:
https://www.ads-software.com/support/topic/142787?replies=16
https://www.ads-software.com/support/topic/96851?replies=5
I think I am a bit out of my depth with the php and sql query end of this.
I have a feeling that I am attempting to do something very similar to the first support link above.
I am working on a website for a non-profit organisation in Ireland and they have a resource library of downloads relating to preventing gender based violence.
You can see a sample of it here:
https://www.gbv.ie/category/resource-library/make-prevention-and-protection-central-to-programming/
As you can see, I have a list of all posts in each category. They have requested that these posts are ordered by Organisation/Author, then year, then title.
So I am using post_meta to get the necessary information associated with each post
<ul> <?php while (have_posts()) : the_post(); ?> <li><?php $key="authors"; echo get_post_meta($post->ID, $key, true);?> (<?php the_time('Y');?>) <a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul>
This gives a display of Author (Year) Title
However, using:
$posts = query_posts($query_string . '&orderby=title&order=asc&posts_per_page=-1');
to order the posts will obviously order by the post titles.
So my basic understanding of the previously mentioned support topics is that I need to do some custom queries to $wpdb and join the necessary meta_key to the post title, thereby allowing my “&orderby=title” to work as planned?
I think I’m probably waaaay off here, but this is my guess as to what I should be looking to do!
<ul> <?php if (in_category('7')) { $pageposts = $wpdb->get_results("SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta author ON (wp_posts.meta_key = 'author') INNER JOIN wp_postmeta year ON (wp_posts.meta_key = 'year') ORDER BY author.meta_value ASC; if ($pageposts) : foreach ($pageposts as $post): setup_postdata($post); ?> <li><?php $key="authors"; echo get_post_meta($post->ID, $key, true);?> (<?php the_time('Y');?>) <a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endforeach;?> <?php endif; } ?> </ul>
Additional Information:
Category Layout:
Resource Library
– sub categories
— some sub sub categoriesAll posts are in_category(‘7’) which is the resource library, as well as whichever sub, or sub-sub category is necessary.
This allows me to use one file “category.php” which has an:
if (in_category('7')) {//use special code } else {//use standard category display};
So yeah. I’m hugely confused, and, well, they’re having a charity dinner thing on Friday and the site needs to be sorted by then so I’m starting to stress out! Any help would be hugely appreciated.
- The topic ‘Create list of posts showing post meta and title – ordered by meta asc’ is closed to new replies.