WordPress.org

Ready to get started?Download WordPress

Forums

My Post Order
Ordering a loop by category (or similar tagging method) (7 posts)

  1. vtmnD
    Member
    Posted 1 year ago #

    I am trying to reorder my global and/or main query so that it reorders all posts by the categories (slugs) they are in. Each post is attached to only one category, because I am trying to use that as a navigation element. On the homepage, all Cat1 post excerpts are displayed, then Cat2, Cat3. If easier I can also try to create custom post meta categories, and order my posts that way.

    I also need pagination to sync, so when clicking on a single post, the previous/next links follow the same order as the homepage loop. I would really like the prev/next to work from one category to another, not just be cat specific. In other words, the next link goes to Cat3 if at the last post in Cat2, or vice versa for previous link.

    Does your My Posts Order wordpress plugin give me that ability to adjust my loop as I have described? What code snippets should I use to make that happen if so? I just need to adjust the order of my query, I don't need a sidebar of links.

    Thanks sincerely for your time and help!

    http://wordpress.org/extend/plugins/my-posts-order/

  2. Kapil Chugh
    Member
    Plugin Author

    Posted 1 year ago #

    Can you explain the same with example or some reference is there.

  3. vtmnD
    Member
    Posted 1 year ago #

    I am just trying to reorder the loop query globally, so that posts that I have determined to go in one category are queried before the next category. I thought I would try to do this with a custom meta value rather than engineer it around category name, so I threw this in the loop:

    <?php
    $args = array(
    			'post_status' => 'publish',
                'meta_key' => 'keyName',
                'orderby' => 'meta_value_num',
                'order' => 'DESC'
            );
    
    $custom_query = new WP_Query($args);
    while($custom_query->have_posts()) : $custom_query->the_post(); 
    
    ?>

    And I also took the trouble to order each post with a meta value, i.e. for Section 1 posts made the values a 1, Section 2's I made a 2, etc. But the loop doesn't execute. Wondering if I am doing something wrong with the syntax?

  4. Kapil Chugh
    Member
    Plugin Author

    Posted 1 year ago #

    Now I got your point.

    (1) Here you need to create sections as much you have categories.

    (2) Assign posts in that section.

    (3) Then call wp_query like this

    $args = array(
    			'section_name' => ' cat1',
    
            );

    Here cat1 must be your name of section not category.

    I think you won't be able to do paging with current version of plugin. You will have to modify it.

    Feel free to ask anything.

  5. vtmnD
    Member
    Posted 1 year ago #

    This is the code I put in at the beginning of my loop, and it doesn't affect the ordering of the posts at all. It just posts in the default order. All four of my categories belong to a corresponding section. I don't get it.

    <?php
    $args = array(
    			'section_name' => 'section1',
    			'section_name' => 'section2',
    			'section_name' => 'section3',
    			'section_name' => 'section4',
            );
    $custom_query = new WP_Query($args);
    while($custom_query->have_posts()) : $custom_query->the_post();
    ?>

    Any ideas?

  6. vtmnD
    Member
    Posted 1 year ago #

    I also tried this, same result.

    <?php
    $args = array(
    			'section_name' => 'section1', 'section2', 'section3', 'section4'
            );
    $custom_query = new WP_Query($args);
    while($custom_query->have_posts()) : $custom_query->the_post();
    ?>
  7. Kapil Chugh
    Member
    Plugin Author

    Posted 1 year ago #

    You need to put only one section name at a time.

    <?php
    $args = array(
    			'section_name' => 'section1'
            );
    ?>

    Please mention URL of website where you are checking this.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic