Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter ncox85

    (@ncox85)

    .

    Thread Starter ncox85

    (@ncox85)

    Working great now. Thanks so much for your help!

    Thread Starter ncox85

    (@ncox85)

    Sorry. I don’t understand that at all.

    I think I made a little progress with the code below. It is sorting correctly with the code below, except it is still showing all posts on the same page, even though I have it set to show only 5 posts per page.

    <?php
    				$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
    				$todaysDate = date('m/d/Y H:i:s');
    				?>
    
    <?php query_posts('paged=' . $paged . 'posts_per_page=5&category_name=classes&meta_key=Date&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC'); ?>
    Thread Starter ncox85

    (@ncox85)

    It is still not sorting. Something about the array is not quite right.

    This code was working, but pagination was broken. I guess my question at this point is how do I translate this code into an array, or insert the $paged variables into this code string?

    <?php query_posts('showposts=5&category_name=classes&meta_key=Date&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC'); ?>

    Thread Starter ncox85

    (@ncox85)

    I am not sure where I would insert the strtotime function. I am a very basic beginner at PHP. Also, would I just substitute meta_value for meta_value_num?

    This is my attempt at implementing your suggestions. It did not change anything on the site.

    <?php
    //Protect against arbitrary paged values
    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
    $todaysDate = date('m/d/Y H:i:s');
    strtotime( $todaysDate );
    
    $args = array(
    	'posts_per_page' => 5,
    	'category_name' => 'classes',
    	'paged' => $paged,
    	'meta_key' => 'date',
    	'meta_value_num' => $todaysDate,
    	'orderby' => 'meta_value_num',
    	'order' => 'ASC',
    );
    
    $the_query = new WP_Query( $args );
    ?>
    Thread Starter ncox85

    (@ncox85)

    I still can’t figure out why this doesn’t work. My custom field key is Date, and the value is formatted mm/dd/yy 00:00:00. I am trying to order the posts by the date in the custom field, which is the meta_value. What am I missing?

    <?php
    //Protect against arbitrary paged values
    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
    $todaysDate = date('m/d/Y H:i:s');
    
    $args = array(
    	'posts_per_page' => 5,
    	'category_name' => 'classes',
    	'paged' => $paged,
    	'meta_key' => 'date',
    	'meta_value' => $todaysDate,
    	'orderby' => 'meta_value',
    	'order' => 'ASC',
    );
    
    $the_query = new WP_Query( $args );
    ?>
    Thread Starter ncox85

    (@ncox85)

    The posts are a list of events. The loop is displaying the posts with most recent posting date first. What I am trying to do is to display them like a calendar list, so the posting date will not be the date of the event. I want to sort by the date of the event, which will be posted days or weeks beforehand, and not necessarily in the order they will occur. I am using the custom fields section on the posts to define the date and time of the event, and the first bit of code above I took from a tutorial on how to sort posts using that custom field. Sorry, I should have explained that better.

    The site is currently being hosted on one of my old domains for development if you want to take a look.

    http://www.ccs-strategies.com

    Thread Starter ncox85

    (@ncox85)

    Here is my extremely amateur attempt at inserting this code and implementing the date sorting. The pagination now works, but the date sorting is not functioning at all. Also, it is showing more than 5 posts per page, even though the posts_per_page variable is set to 5. How far off am I?

    <?php
    //Protect against arbitrary paged values
    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
    $todaysDate = date('m/d/Y H:i:s');
    
    $args = array(
    	'posts_per_page' => 5,
    	'category_name' => 'classes',
    	'paged' => $paged,
    	'meta_key' => 'date',
    	'meta_value' => $todaysDate,
    	'orderby' => 'meta_value',
    	'order' => 'ASC',
    );
    
    $the_query = new WP_Query( $args );
    ?>
    Thread Starter ncox85

    (@ncox85)

    Thanks so much for the reply. This will work to limit the loop to one category, but my bigger problem is how to use the same $args method to sort by date. I dont know how to transfer the code I have now into the array, or if I need to do it a different way.

Viewing 9 replies - 1 through 9 (of 9 total)