• Hi all,

    Hope someone finds this easy and can let me know how I can add a small code to remove a single category from the bellow. The category ID is 61 and I have tried <?php query_posts(‘cat=-61’); ?> to no avail.

    <?php
    global $post;
    $myposts = get_posts(array(‘numberposts’ => 4, ‘offset’ => 0,’post_status’=>’publish’));
    foreach($myposts as $post) :
    setup_postdata($post);
    ?>

    Many thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try adding the ‘cat’ parameter to you r get_posts() call, like this:

    $myposts = get_posts(array('numberposts' => 4, 'offset' => 0,'post_status'=>'publish', 'cat' => -61));
    Thread Starter jcyyap

    (@jcyyap)

    thanks vtxyzzy,

    I tried your suggestion but still doesn’t work.

    Any other suggestions?

    thanks

    Try using ‘category’ => -61 instead of ‘cat’ => -61.

    I personally find it much easier to read above when it is shown as such. (Just a note and reminder to self that the args go first):

    $myposts = get_posts(
    array(
    'numberposts' => 4,
    'offset' => 0,
    'post_status'=>'publish',
    'cat' => -61)
    );

    Would this be an improvement?:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
    'paged' => $paged,
    'posts_per_page'=> 4,
    'post_status'=>'publish',
    'cat' => -61
    );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post);
    ?>

    But is not post_status'=>'publish' the default and not required?

    Note: Make sure to match the posts per page with the Reading Settings if using a Pagination Plugin…or a fallback to default pagination.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Remove single category from latest posts’ is closed to new replies.