Jump to content

Recommended Posts

Hi,

 

I've setup custom taxonomies called months and years

Months has

dec-jan

feb-mar

apr-may

etc

 

Years has

2011

2010

2009

 

I can then assign a post to a month and a year

 

What I'm trying to do is then get a page to show all posts as follows:

 

aug - sept 2011

- post 1

- post 2

jun - jul 2011

- another post

- another post

 

However, I can't get my code to work, here's my query:

 

$querystr = "
SELECT *  FROM $wpdb->posts 
LEFT JOIN $wpdb->term_relationships 
ON($wpdb->posts.ID = $wpdb->term_relationships.object_id) 
LEFT JOIN $wpdb->term_taxonomy 
ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) 
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id) 
WHERE $wpdb->posts.post_type = 'post'  
AND $wpdb->posts.post_status = 'publish' 
AND $wpdb->term_taxonomy.taxonomy = 'months' 

ORDER BY $wpdb->term_taxonomy.taxonomy = 'years'  DESC  
";

I then use:

 

 

<?php
$pageposts = $wpdb->get_results($querystr, OBJECT);
?>
<?php if ($pageposts): ?>
<?php global $post; ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>

<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <?php the_title(); ?></a><br>

<?php endforeach; ?>
<?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>

But it just shows a list of posts. It doesn't order them and I can't work out how to add the headings

 

Can someone help?

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/245090-wordpress-filter-by-taxonmoies/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.