0

I'm setting some featured content through the customizer (it's saved in theme_mod);

Using the pre_get_posts hook, I'm retireving the feature pages in this way:

add_action('pre_get_posts','alter_query');

function alter_query($query){    
 $foo = array('one'   => get_theme_mod("featured_content_one", "default_value" ),
              'two'   => get_theme_mod("featured_content_two", "default_value" ),
              'three' => get_theme_mod("featured_content_three", "default_value" ),
              'four'  => get_theme_mod("featured_content_four", "default_value" ),
);

        if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'post_type',  'page'  );
        $query->set ('post__in', $foo ) ;

    }
}

Currently I'm retrieving the content but the $query object post__in property won't allow duplicate content( and I need it for structure markup..).

The problem is I can't find a property that accepts my array of page ids and (possibly) outputs this array keeping the input order.

  • pre_get_posts is meant for altering the query, but not in the way you're attempting. you might want to use the the_content filter, checking for is_main_query() and is_front_page() etc – karpstrucking Feb 13 '15 at 13:11
  • I can pick up posts through $query->set('post__in', array(12,16)) but I haven't found a working argument for pages.. could you explain why pre_get_posts is no good , does it depend from the post-type? – maioman Feb 13 '15 at 15:35
  • ah, I think I misunderstood your intention based on the format of your $foo array. have you tried using passing an array of page ids to post__in? – karpstrucking Feb 13 '15 at 20:00

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.