• Resolved RyanPrentiss

    (@ryanprentiss)


    What I want it to do:
    Retrieve all posts with a “osiris_slider-main” value.

    What its doing:
    I am receiving the first sticky post, which doesn’t even contain that value.

    index.php

    $slider = new WP_Query(
         array(
              'post_type' => 'any',
              'meta_query' => array(
                   array(
                        'key' => 'osiris_slider-main',
                        'value' => '',
                        'compare' => 'NOT LIKE'
                   )
              ),
              'orderby' => 'date'
         )
    );
    print_r($slider);

    Any help would be greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’d try something like the following which should return all posts that have the ‘osiris_slider-main’ meta key.

    $slider = new WP_Query(
         array(
              'post_type' => 'any',
              'meta_key' => 'osiris_slider-main',
              'orderby' => 'date'
         )
    );
    print_r($slider);
    Thread Starter RyanPrentiss

    (@ryanprentiss)

    Thanks jkovis…

    That was my original code, but I’ve since figured out the issue;

    I just need to add “‘ignore_sticky_posts’ => 1” to the array… solved everything.

    Current code is:

    $slider = new WP_Query(
         array(
              'ignore_sticky_posts' => 1,
              'post_type' => 'any',
              'meta_key' => 'osiris_slider-main',
              'orderby' => 'date',
              'nopaging' => true,
              'posts_per_page' => 5
         )
    );

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't get WP_Query to work properly’ is closed to new replies.