3

I use the following codes to get posts only from 'image' post format and it works.

<?php if( has_post_format('image')){ ?>
   <?php the_post_thumbnail(); ?>
<?php } ?>

I also need to get posts only from 'standard' post format with the following codes, but it get post from all post formats.

 <?php if( has_post_format('standard')){ ?>
     <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
 <?php } ?>

Any solutions?

2 Answers 2

4

Do,

<?php if( false == get_post_format() ){ ?>
    <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
<?php } ?>

The standard post format isn't actually a post format, so if you conditionally check whether a post contains a post format (other than the default standard), it will return false, because it's set to... standard.

2
  • Thanks for your answer, I also found a way myself: if( !get_post_format() ). this code also works nice.
    – User1212
    Commented Jun 16, 2013 at 11:53
  • No problem. !get_post_format() is essentially doing the same thing, ! aka NOT, but technically the above would be better written as get_post_format() === false, which will only return true when get_post_format() returns false, which it does when checking for the standard post type. Now, false == will also return true for an empty string '', null and 0, so if they are not the expected, anticipated or potential values of output then it's best to go with === IMO. But glad your problem is solved.
    – Adam
    Commented Jun 16, 2013 at 13:00
0

Try this: Exclude all rest terms using 'NOT IN' operator.

$args = array(
    'orderby'   => 'desc',
    'posts_per_page'    => '4',
    'tax_query'             => array( array(
        'taxonomy'          => 'post_format',
        'field'             => 'slug',
        'terms'             => array('post-format-aside', 'post-format-gallery', 'post-format-link', 'post-format-image', 'post-format-quote', 'post-format-status', 'post-format-audio', 'post-format-chat', 'post-format-video'),
        'operator'          => 'NOT IN'
    ) ),                   
);
1
  • Welcome to wpse! Your question is incomplete, you only created a variable that I assume you will use as a argument for get_posts() OR WP_query, going by OPs question, could you create a complete example on how to achieve that? Commented Oct 23, 2021 at 17:01

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.