How to Link to all posts that have the Standard Post Format

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

🙁 Any hints? All the other formats work.

Related posts

Leave a Reply

3 comments

  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.

  2. 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. 😀

    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!