• I am using WP as a CMS and I’m trying to figure out the best and easiest way to arrange post inside of a category. I know I can just change the dates but then that changes my “newest post” list.
    I was wondering if there is a way to drag and drop the post like you can with several plugins for page order?
    What I doing this for is, I have a list of albums and I would like to have them listed in order by year. The problem is that when I get a new album that fits in between two albums already posted. I want to be able to put the new album in the correct order in my post order but I want the new post to retain the current post date so that it will still be listed as my most resent addition.

    If anyone can please help me I would greatly appreciate it.

Viewing 15 replies - 1 through 15 (of 23 total)
  • Do you have the year added to the post as a custom field? If so, you can sort that category based on the custom field, with this handy plugin:

    http://www.dyasonhat.com/wordpress-plugins/smart-sort-wordpress-plugin-sort-posts-by-custom-field/

    You could use a custom field for the album year and then sort the custom select query results by the album year meta value.

    ORDER BY $wpdb->postmeta.meta_value ASC

    http://codex.wordpress.org/Using_Custom_Fields
    http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

    Thread Starter allshookup

    (@allshookup)

    Thanks for the help guys…

    But, I still don’t have it yet… (sorry newbie)

    I have added a custom field key of “release_date” then a value of “01-01-08” (or what ever the release date is…)

    How would I write the loop to display this on a page?
    I just know enough about coding and loops to be dangerous.

    My category is 20 here is the code I am currently using to display the post in the default order… It is most like not the best code… sorry.

    <?php rewind_posts(); global $more; $more = 0;
    
    	$my_query = new WP_Query('cat=20&showposts=500');
             while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>
    
    <div class="post" id="post-<?php the_ID(); ?>">
    				<h1><?php the_title(); ?></a></h1>
    
    				<div class="entry">
                    <?php global $more; $more = false; ?>
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
    
    			</div>
    
    <hr />
     <?php endwhile; ?>
    Thread Starter allshookup

    (@allshookup)

    OKAY!!!

    I have used the http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query
    and have got it to only display the post with a key of “release date” the problem is I don’t know how to get it to sort by the value? Please help me finish this… ๐Ÿ™‚
    Here is the new code that I am using…

    <?php
    
     $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = 'release-date' 
    
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        AND wposts.post_date < NOW()
        ORDER BY wposts.post_date DESC
     ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    ?>
     <?php if ($pageposts): ?>
      <?php foreach ($pageposts as $post): ?>
        <?php setup_postdata($post); ?>
    
        <div class="post" id="post-<?php the_ID(); ?>">
          <h2><?php the_title(); ?></h2>
                <div class="entry">
             <?php the_content('Read the rest of this entry ยป'); ?>
          </div>
    
        </div><hr />
      <?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 endif; ?>

    Replace:

    ORDER BY wposts.post_date DESC

    With:

    ORDER BY $wpdb->postmeta.meta_value ASC

    Or:

    ORDER BY $wpdb->postmeta.meta_value DESC

    Thread Starter allshookup

    (@allshookup)

    hmmm…

    I did swap the code out but all I get on the web page now is the
    “Not Found” error message?
    I know were close ๐Ÿ™‚

    Thread Starter allshookup

    (@allshookup)

    Well I kept tweaking it and got it working!

    I was wondering how can I limit the query to just one category?

    Thanks again for all the help!

    Try using this $querystr with the term_taxonomy.term_id equal to your category ID (here it is for category 44):

    $querystr = "
    SELECT * FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    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)
    WHERE $wpdb->term_taxonomy.term_id = 44
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'release-date'
    ORDER BY $wpdb->postmeta.meta_value ASC
    ";
    Thread Starter allshookup

    (@allshookup)

    You are the master! Thank you so much!

    I have also a special need regarding posts order under certain category… Ive been looking around and I cant find a plug in or a trick to do it.

    On my WP I have a category called “Events” where people send me flyers and info about their events so I need to have them posted on a specific order… by the date of the event not the date I posted since some people send me a their info way before the event comes.

    I need to customize the order of each post something like you can do with the pages order…

    Thanks in advance for your help

    I’m trying to do the same as allshookup but somehow the code doesnt work to me… if I apply it like iridiax gave it all my posts become the same one and just repeat it self…

    This is the code Im using:

    <?php
    
     $querystr = "
        SELECT wposts.*
    	LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    	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)
    	WHERE $wpdb->term_taxonomy.term_id = 5
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = 'Eventos' 
    
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        AND wposts.post_date < NOW()
        ORDER BY $wpdb->postmeta.meta_value ASC
     ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    ?>
     <?php if ($pageposts): ?>
      <?php foreach ($pageposts as $post): ?>
        <?php setup_postdata($post); ?>
    
      <?php endforeach; ?>
    
      <?php else : ?>
    
     <?php endif; ?>

    Anybody knows what I’m doing wrong?

    If you are trying to do the same thing as allshookup, then I’d stick with the $querystr code posted here, and just change the category ID and the name of the meta key. Your code is not the same and contains errors. Also, you need something like <?php the_content('Read the rest of this entry ยป'); ?> inside your foreach.

    $querystr = "
    SELECT * FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    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)
    WHERE $wpdb->term_taxonomy.term_id = 5
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'Eventos'
    ORDER BY $wpdb->postmeta.meta_value ASC
    ";

    Thanks a lot iridiax!

    Its working now … the only problem is that its showing the posts from the category 5 under every category!

    Seems like is not respecting the taxonomy id and overwrites the other categories

    Any suggestions?

    Hi there

    Thank goodness I found this page. Have been searching for hours for the solution this page addresses.

    Unfortunately, I’m having a little trouble getting it to work. I really have tried multiple options but I’m getting no entries. I wonder if someone could reproduce please the final code they’re using to make this work (including whatever one needs to make this work within a query_posts loop)?

    Would be very grateful.

    Richard

    P.S. In case it helps, this is the current code I’m trying use:

    <h5>Events</h5>
    
    			<?php
    
    		$querystr = "
    		SELECT * FROM $wpdb->posts
    		LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    		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)
    		WHERE $wpdb->term_taxonomy.term_id = 4
    		AND $wpdb->term_taxonomy.taxonomy = 'category'
    		AND $wpdb->posts.post_status = 'publish'
    		AND $wpdb->postmeta.meta_key = 'Event_date'
    		ORDER BY $wpdb->postmeta.meta_value ASC
    		";
    
    			 $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    			?>
    			 <?php if ($pageposts): ?>
    			  <?php foreach ($pageposts as $post): ?>
    			    <?php setup_postdata($post); ?>
    
    			  <?php endforeach; ?>
    
    			  <?php else : ?>
    
    			 <?php endif; ?>
Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘Arrange Post Order?’ is closed to new replies.