• Hi all,

    I’m trying to create a custom feed which grabs the days posts and then puts them all in alphabetical order. I can get them in alphabetical order or I can get all the days posts. However once I filter by date and then try to order them by title nothing happens.

    The code I’m using is here:

    <?php
    $current_date = getdate();
    $args = array(
    	'posts_per_page'   	=> 90,
    	'year'     			=> $current_date["year"],
    	'monthnum' 		=> $current_date["mon"],
    	'day'				=> $current_date["mday"],
    	'orderby' 			=> 'title',
    	'order'    			=> 'ASC'
    
    );
    query_posts( $args );
    include('wp-includes/feed-rss2.php');
    ?>

    You can see a sample of the feed here:

    feed://members.maxwelllucas.com/blog/?feed=gw-news

    Any help would be much appreciated.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi I am having the same difficulties, have you found a way to fix this ?

    Thanks.

    Thread Starter antonyjosephsmith

    (@antonyjosephsmith)

    I’m aware of a solution but haven’t had chance to try fix it yet. Are you any good with PHP? The answer lies in here:

    Having looked at the documentation and source code for the query_posts() function, it uses the $GLOBALS super-global array, so unless you call wp_reset_query() afterwards, further queries may not behave as expected.

    Since the function returns an array of posts, my suggestion would be to use the PHP internal function usort() (https://uk3.php.net/usort). This allows you to sort a multi-dimensional array by user-defined criteria. In this case I would suggest pulling out the days’ posts using query_posts (or get_posts(), which has less side effects), then usort() the resulting array to alphabetise the array on the title array element.

    The PHP manual gives a simple example fo how this could work:

    <?php

    function compare($a, $b) {
    return strcmp($a[“fruit”], $b[“fruit”]);
    }

    $fruits[0][“fruit”] = “lemons”;
    $fruits[1][“fruit”] = “apples”;
    $fruits[2][“fruit”] = “grapes”;

    usort($fruits, “cmp”);

    Which, if you output the contents of the $fruits array, gives you:

    apples
    grapes
    lemons

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Feed Orderby has no effect’ is closed to new replies.