I created a customizer setting where it's possible to choose a list of pages. This list of pages will be shown with a different style, only in pages using a specific template, together with more content.

Doing print_r on this setting shows an array of this type:

Array (
    [0] => Array ( [page] => 701 )
    [1] => Array ( [page] => 156 )
    [2] => Array ( [page] => 1133 )

Then, i'm using a foreach loop to convert it in a suitable form for post__in, to add as arg for a WP_Query.

foreach ($services as $service) {
    $id = $service['page'];

    $id_list [] = $id;

where $services is obtained by get_theme_mod and contains the correct page ids.

Then, i'm passing it to WP_Query this way:

$args = array(
    'post__in' => $id_list,
    'ignore_sticky_posts' => true

$q = new WP_Query($args);

But query is returning no page despite the fact all ids are correct. As add-up, i may say that this query is being run on the homepage, and there is a standard query running after this; wp_reset_postdata is called.

Since i tried as well to hardcode my array and result is the same, what's wrong? Thank you.

  • Are those IDs page or post post type? – Milo Jun 1 '17 at 17:37
  • @Milo I didn't care until now. It's page for all of them – Daniele Squalo Jun 1 '17 at 17:38
  • 1
    the you must set post_type to page or it will default to post. – Milo Jun 1 '17 at 17:38
  • It worked, thank you. Now i know one more thing :D – Daniele Squalo Jun 1 '17 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.