• Resolved bradleekw

    (@bradleekw)


    Hello everyone

    I have looked around for problems similar to mine but I can’t seem to find any solutions. I am using the get_posts function with the parameter array found at https://codex.www.ads-software.com/Template_Tags/get_posts

    The way I am using the array is like this:

    
    $args = array( 'posts_per_page' => -1, 'offset' => 0, 'category' => 9, 'orderby' => 'ID', 'order' => 'ASC'  );
    $myposts = get_posts( $args );

    It returns the category I select but I can change the other parameters such as “orderby” and “order” and it makes no difference on the order of the posts. “posts-per_page” and “offset” do change what is returned.

    Any help on this topic will be greatly appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Your code is fine. More than likely some other code is altering your arguments through an action or filter, such as “pre_get_posts”. You can narrow down the source by disabling all plugins and switching to the twentysixteen theme. Add you code to a template file. Maintain a clean copy to restore to the theme. The ordering should work fine.

    Switch back to your theme and retest. Activate plugins one at a time, testing after each. When you ordering fails, the last activated code is the problem.

    Thread Starter bradleekw

    (@bradleekw)

    So sorry about the late reply!

    Thank you for the advice, although I didn’t read it at the time it is what I ended up doing ??

    I was using a re-ordering plugin to change the order of posts. After disabling this plugin everything started working correctly again.

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_posts array parameters not changing’ is closed to new replies.