1

Why doesn't this work?! <?php echo get_post_format_link('standard');?>

:( Any hints? All the other formats work.

2
  • wproots.com/using-wordpress-post-formats-to-their-fullest Down the bottom there's a snippet about archives.
    – user8782
    Commented Sep 20, 2011 at 5:25
  • "Standard" is not a post format - it's the absence of a post format. Therefore, when no post format is set (ie: standard post), the post-format-* taxonomy is not set, and the call get_term_link() used in this function will fail.
    – shea
    Commented Dec 7, 2012 at 21:54

3 Answers 3

1

Put this in your function.php

function akv3_query_format_standard($query) {
    if (isset($query->query_vars['post_format']) &&
        $query->query_vars['post_format'] == 'post-format-standard') {
        if (($post_formats = get_theme_support('post-formats')) &&
            is_array($post_formats[0]) && count($post_formats[0])) {
            $terms = array();
            foreach ($post_formats[0] as $format) {
                $terms[] = 'post-format-'.$format;
            }
            $query->is_tax = null;
            unset($query->query_vars['post_format']);
            unset($query->query_vars['taxonomy']);
            unset($query->query_vars['term']);
            unset($query->query['post_format']);
            $query->set('tax_query', array(
                'relation' => 'AND',
                array(
                    'taxonomy' => 'post_format',
                    'terms' => $terms,
                    'field' => 'slug',
                    'operator' => 'NOT IN'
                )
            ));
        }
    }
}
add_action('pre_get_posts', 'akv3_query_format_standard');
More information here.

0
<?php
$args = array(
'showposts' => 9,
'tax_query' => array(
        array( 'taxonomy' => 'post_format',
              'field' => 'slug',
              'terms' => array('post-format-video','post-format-quote'),
              'operator' => 'NOT IN'
              )
        )
);
query_posts( $args );
while ( have_posts() ) : the_post(); ?>

    <?php the_title(); ?>

<?php endwhile; wp_reset_query(); ?>

from

http://www.tristarwebdesign.co.uk/blog/wordpress/query-by-post-format-in-wordpress/

3
  • ...yeah that's great for displaying them, which isn't my problem. I just want to link to them on their "archive" page if that makes sense. I guess I could create a custom archive page to display only the standard post formats and then link to it, but that's kind of a pain in the ass, don't you think? Is there an easier way? Commented Jul 12, 2011 at 3:22
  • Unfortunately I believe this is the only way to currently do this. As miqronaut explains below, there is no identifiable record added to the db linking a post as a 'standard' format. Only solution seems to be excluding all other formats for now. I ended up having to create a custom archive page with a custom loop similar to the one above to accomplish the same thing you are asking.
    – shawn
    Commented Jul 12, 2011 at 6:10
  • It's a tricky thing to do, I thought they would have sorted it out by now to be honest! Commented Jul 12, 2011 at 19:12
0

When you assign a non-Standard post format to a post, a record gets added to the wp_term_relationships table. This record contains your post number and the term_taxonomy_id, which joins via wp_term_relationships to the post format in wp_terms. When you assign a Standard post format to a post, no record for post format is added to wp_term_relationships. If it was previously assigned another post format and changed to Standard, the record is removed from wp_term_relationships. Unfortunately, get_post_format_link relies on having that record in wp_term_relationships, so won't work with Standard post format.

For example, when I changed a post's post format to image, a record was added to wp_term_relationships, which eventually pointed to wp_terms >> post-format-image. When I changed the post's post format to Standard, this record disappeared. In WP's codebase, get_post_format_link uses get_term_by('slug', 'post-format-' . $format, 'post_format' ), and with the missing related post format record for Standard, we all lose. :-D

This might answer your original question of why it doesn't work. I wish that I could offer a slick solution, especially given your immensely helpful WordPress posts!

1
  • miqronaut - Thanks for your explanation. I suspected something like this was the case. Seems like so much work to have to exclude all other formats in order to show the most normal kind of post ;) I'd say this is a borderline bug but I'm sure it probably affects very few people. I was just hoping there was an easier way that I was somehow missing. Commented Jul 12, 2011 at 6:24

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.