Support » Plugin: WP RSS Aggregator » Sort Individual Feeds

  • Resolved sojournerweb

    (@sojournerweb)


    Hi, I was provided the following code to place in theme function file to sort ascending and show future posts:

    add_filter( ‘wprss_display_feed_items_query’, ‘my_show_future_posts’, 10, 2 );
    function my_show_future_posts( $args, $settings ) {
    $args[‘order’] = ‘ASC’; // Reverses the sort order
    $args[‘post_status’] = array(‘publish’, ‘future’);

    return $args;
    }

    My question is, there is one specific feed I want to sort descending. How can I specify the one feed to sort descending, while having the other sort ascending?

    Thanks

    https://wordpress.org/plugins/wp-rss-aggregator/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    Please go through this documentation page which shows how to change the order based on the feed source ID.

    Regards

    Chirag,

    Hi, I tried this method, but it didn’t work.

    Out of curiosity, I also tried the following code, but this does not work. This makes me think that the particular array variable you mentioned does not exist:

    add_filter( ‘wprss_display_feed_items_query’, ‘my_show_future_stories’, 10, 2 );
    function my_show_future_stories( $args, $settings ) {
    if (isset($args[‘meta_query’][‘wprss_feed_id’])) {
    $args[‘order’] = ‘ASC’;
    $args[‘post_status’] = array(‘publish’, ‘future’);
    }
    return $args;
    }

    I am using version 4.8.1, which looks like it just came out a few hours ago.

    Plugin Author Xedin Unknown

    (@xedinunknown-1)

    Hi sojournerweb,

    There are a number of key steps to take in order for you to achieve what you want.

    1. Understand what you are sorting by;
    2. Determine how you are displaying the feed items;
    3. Understand the parameters.

    1. This is the most straight-forward one. If you are sorting by post_date, you can skip this. Otherwise, see point 3.
    2. This is most important. Logically, it is not possible to sort items differently for feed sources in the same query. However, it’s possible to change sort order depending on the feed source ID. What you could do is detect the presence of a specific source ID, and change the sort order accordingly. Thus, if that ID is present in the list of IDs you supply via the shortcode, the items will be sorted one way, if not – then another way.
    3. Most technical part.
    If you are sorting by something other than post_date, see this page.
    The IDs of the feed sources that are passed to the shortcode are in an array that is stored in $args['meta_query']['wprss_feed_id']. It’s a numeric array, so you would probably have to use in_array().

    I hope this helps. Please give it a go and let us know if it doesn’t work!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sort Individual Feeds’ is closed to new replies.