Grow your CSS skills. Land your dream job.

posts and pages In WordPress home

  • # February 1, 2013 at 8:17 pm

    I am using a function in functions.php to get posts and pages displayed on the homepage.


    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    if ( is_home()) {
    $query->set( 'post_type', array( 'post', 'page') );
    $query = apply_filters( 'the_content', $query);
    return $query;
    }
    }

    I noticed that by doing this, the page does not render shortcodes and ignores the fact that a page template is assigned to the page. So I tried using passing the return $query through a filter like so

    $query = apply_filters( ‘the_content’, $query);

    but then I get this error Object of class WP_Query could not be converted to string

    I don’t know any way around it. Do you?

    # February 1, 2013 at 9:19 pm

    It’s because you’re trying to return an object. You have to use references.

    i.e.

    return $query->reference;

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".