1

Hi i am currently building upon a theme that i have build previously for my blog. The following code is to point to the latest post (the featured post). As this will have a different styling than all the other posts. However. I would like to filter out the post-format: links using the WP-Query i have defined within the loop since it brings me a lot more flexibility. How would i go around doin that?

 <?php $featured = new WP_Query();  $featured->query('showposts=1'); ?>
                    <?php while ($featured->have_posts()) : $featured->the_post(); ?>
                    <h2><a href="<?php the_permalink(); ?>" rel="bookmark" class="maintitle"><?php the_title(); ?></a></h2>
                            <?php the_excerpt(); ?>
                            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="btn">Read more &raquo;</a> 

Best Regards Lucas

1
  • do you mean "post_type"? Commented Aug 5, 2011 at 14:54

1 Answer 1

2

You should be able to exclude posts with a specific format using WP_Query's tax_query parameter.

Eg.

$q_args = array( 
    'posts_per_page' => 1, 
    'tax_query' => array(
        array(
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => array( 'post-format-link' ),
            'operator' => 'NOT IN'
        )
    )
);
$featured->query( $q_args );

Untested, but should do the trick..

3
  • Sorry the code didnt function as needed i got an error from calling the query at line 16 Fatal error: Call to a member function query() on a non-object in /home/www/dechowmedia.com/wp-content/themes/portfolio/index.php on line 16
    – user7686
    Commented Aug 6, 2011 at 10:10
  • The code i posted should only replace the $featured->query('showposts=1'); part of your original code, incase that wasn't obvious/clear.
    – t31os
    Commented Aug 6, 2011 at 10:44
  • If you received the answer you were looking for, please mark this answer correct, and i welcome the edit as you were indeed correct regarding the term slug.
    – t31os
    Commented Dec 9, 2011 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.