WordPress.org

Ready to get started?Download WordPress

Forums

Arrange Post Order? (24 posts)

  1. allshookup
    Member
    Posted 6 years ago #

    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.

  2. Ivovic
    Member
    Posted 6 years ago #

    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/

  3. iridiax
    Member
    Posted 6 years ago #

    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

  4. allshookup
    Member
    Posted 6 years ago #

    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; ?>
  5. allshookup
    Member
    Posted 6 years ago #

    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; ?>
  6. iridiax
    Member
    Posted 6 years ago #

    Replace:

    ORDER BY wposts.post_date DESC

    With:

    ORDER BY $wpdb->postmeta.meta_value ASC

    Or:

    ORDER BY $wpdb->postmeta.meta_value DESC

  7. allshookup
    Member
    Posted 6 years ago #

    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 :)

  8. allshookup
    Member
    Posted 6 years ago #

    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!

  9. iridiax
    Member
    Posted 6 years ago #

    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
    ";
  10. allshookup
    Member
    Posted 6 years ago #

    You are the master! Thank you so much!

  11. baalam
    Member
    Posted 6 years ago #

    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

  12. baalam
    Member
    Posted 6 years ago #

    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?

  13. iridiax
    Member
    Posted 6 years ago #

    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
    ";
  14. baalam
    Member
    Posted 6 years ago #

    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?

  15. nzde
    Member
    Posted 6 years ago #

    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

  16. nzde
    Member
    Posted 6 years ago #

    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; ?>
  17. baalam
    Member
    Posted 6 years ago #

    Hi nzde

    Here's mine
    My category number was 5 so I created a new template called category-5.php so you have to call it category-4.php and this is the complete code with your variables

    <?php get_header(); ?><?php get_sidebar(); ?>
    <div id="wrapper">
    
    	<div class="mission">
    
    	<?php
    
            if((function_exists('ls_getinfo')) && (ls_getinfo('isref'))) { ?>
    <h2><?php ls_getinfo('terms'); ?></h2>
    
    p>You came here from <?php ls_getinfo(‘referrer’); ?> searching for <i><?php ls_getinfo(‘terms’); ?></i>. These posts might be of interest:</p>
    <ul>
    <?php ls_related(5, 10, '<li>', '</li>', '', '', false, false); ?>
    </ul>
      <?php }   else { ?>
    <?php } ?></div>
            <div id="content">
    <?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); ?>
    
        <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; ?>
            </div>
    </div>
    <?php get_footer(); ?>
  18. nzde
    Member
    Posted 6 years ago #

    Many thanks baalam. Really appreciate it; extremely helpful.

    The only problem I'm left with concerns the method of date input I'm using for the custom field. I'm currently requiring dates to be entered in the format mm-dd-yyyy, but the above code won't order the output dates chronologically. This rough, demo output list shows you what I mean:

    event 01-31-2009- 18 June 2008 - 0 comments
    event 06-20-2008- 18 June 2008 - 0 comments
    event 08-15-2008- 18 June 2008 - 0 comments
    event 10-21-2010- 18 June 2008 - 0 comments
    event 12-01-2008- 18 June 2008 - 0 comments

    The seemingly obvious reason is that the system is only reading the first two digits, and ordering by reference to those.

    Can anyone help me please with what sort of date input structure I should use (for my custom text field) to make the output chronologically ordered when using the code above?

    Many thanks for your help.
    Richard

  19. baalam
    Member
    Posted 6 years ago #

    I have to give a special value

    001 will be the event I want at the top of the page
    The second one I gave the value 007 so it goes tot he second place and it gives me a range of 6 events to add in between

    I don't know if I'm clear enough

  20. LeSte
    Member
    Posted 6 years ago #

    here is a querystr im using:


    $querystr = "
    SELECT $wpdb->posts.*
    FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
    WHERE $wpdb->postmeta.meta_key = 'views'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->posts.post_type = 'post'
    ORDER BY ($wpdb->postmeta.meta_value + 0) DESC LIMIT 3,11;
    ";

    I'd like to add a category condition but dont know how to add it... can anyone tell me please ?

  21. LeSte
    Member
    Posted 6 years ago #

    i've tried this:


    $querystr = "
    SELECT $wpdb->posts.*
    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 = $cat_ida
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    WHERE $wpdb->postmeta.meta_key = 'views'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->posts.post_type = 'post'
    ORDER BY ($wpdb->postmeta.meta_value + 0) DESC LIMIT 3,11;
    ";

    but this doesnt work.. any hint ?

  22. nzde
    Member
    Posted 6 years ago #

    Hi there - I've now got this working by using a custom field entry in which I insert dates using this pattern: yyyy-mm-dd, where 1 July 2008, for example, would be 2008-07-01. This works perfectly in ordering the dates chronologically, with the closest date at the top of the list.

    One question I now have please is whether anyone knows how to insert a bit of code into what balaam really helpful gave us above, to limit the number of posts that appear to a determined number, say the first five?

    Would be very grateful if anyone can assist. I know how to do this with a general post query, e.g.:

    <?php query_posts('showposts=5&cat=4'); ?>

    but that doesn't seem apt in the code above.

    Can anyone help please?

  23. fas.khan
    Member
    Posted 5 years ago #

    Simple Solution of the originally asked question.

    http://joelstarnes.co.uk/blog/postmash/

  24. oltdev
    Member
    Posted 5 years ago #

    You may wish to check these plugins:
    custom-post-order and postmash

Topic Closed

This topic has been closed to new replies.

About this Topic