3

I saw a a url path to display all posts of a particular 'format' a few weeks ago, but I've lost the link. Does anyone know the path?

It will be something like

mywebsitex.com/format/image

Works on a standard WP install

mywebsitex.com/type/image/

Any ideas?

1 Answer 1

7

The post format taxonomy:

The post format is a default taxonomy, registered with:

register_taxonomy( 'post_format', 'post', array(
            'public' => true,
            'hierarchical' => false,
            'labels' => array(
                    'name' => _x( 'Format', 'post format' ),
                    'singular_name' => _x( 'Format', 'post format' ),
            ),
            'query_var' => true,
            'rewrite' => $rewrite['post_format'],
            'show_ui' => false,
            '_builtin' => true,
            'show_in_nav_menus' => current_theme_supports( 'post-formats' ),
    ) );

where

$rewrite['post_format'] = $post_format_base ? array( 'slug' => $post_format_base ):false;

and

$post_format_base = apply_filters( 'post_format_rewrite_base', 'type' );

Note that the taxonomy slug is post_format and the rewrite slug is type.

The post format terms:

We can see the available post formats from the get_post_format_strings() function:

/**
 * Returns an array of post format slugs to their translated and pretty display versions
 * 
 * @since 3.1.0
 *
 * @return array The array of translated post format names.
 */
function get_post_format_strings() {
        $strings = array(
                'standard' => _x( 'Standard', 'Post format' ), // Special case. any value that evals to false will be considered standard
                'aside'    => _x( 'Aside',    'Post format' ),
                'chat'     => _x( 'Chat',     'Post format' ),
                'gallery'  => _x( 'Gallery',  'Post format' ),
                'link'     => _x( 'Link',     'Post format' ),
                'image'    => _x( 'Image',    'Post format' ),
                'quote'    => _x( 'Quote',    'Post format' ),
                'status'   => _x( 'Status',   'Post format' ),
                'video'    => _x( 'Video',    'Post format' ),   
                'audio'    => _x( 'Audio',    'Post format' ),
        );
        return $strings;
}

The terms have the slug post-format-{$format} where $format can be one of:

aside, chat, gallery, link, image, quote, status, video, audio

where standard is not included.

The post format rewrite rules:

Here you can see the corresponding generated rewrite rules:

Rewrite Rules

according to the Monkeyman Rewrite Analyzer.

The post format public queries:

We can therefore use the following public queries:

http://example.tld/type/post-format-aside/
http://example.tld/type/post-format-chat/
http://example.tld/type/post-format-gallery/
http://example.tld/type/post-format-link/
http://example.tld/type/post-format-image/
http://example.tld/type/post-format-quote/
http://example.tld/type/post-format-status/
http://example.tld/type/post-format-video/
http://example.tld/type/post-format-audio/

to display all posts in a given post format.

Update:

@ToddBenrud said he managed to get:

http://example.tld/type/image/

to work.

The reason for that is the following request filter:

/**
 * Filters the request to allow for the format prefix.
 *
 * @access private
 * @since 3.1.0
 */
function _post_format_request( $qvs ) {
        if ( ! isset( $qvs['post_format'] ) )
                return $qvs;
        $slugs = get_post_format_slugs();
        if ( isset( $slugs[ $qvs['post_format'] ] ) )
                $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ];
        $tax = get_taxonomy( 'post_format' );
        if ( ! is_admin() )
                $qvs['post_type'] = $tax->object_type;
        return $qvs;
}
add_filter( 'request', '_post_format_request' );

This means that a request with the query variable:

Array
(
    [post_format] => image
)

is modified to the correct term name:

Array
(
    [post_format] => post-format-image
    [post_type] => Array
        (
            [0] => post
        )
)

So we could also use:

http://example.tld/type/aside/
http://example.tld/type/chat/
http://example.tld/type/gallery/
http://example.tld/type/link/
http://example.tld/type/image/
http://example.tld/type/quote/
http://example.tld/type/status/
http://example.tld/type/video/
http://example.tld/type/audio/
2
  • I think this line, 'standard' => _x( 'Standard', 'Post format' ), confuses many people :-). Had a slight quarrel with someone in the week about this. standard is not a post format, but just a fall back if no post format is selected for the specific post. I think your post also enforces this point Commented Feb 8, 2015 at 7:14
  • yes this can be rather confusing ;-) Since this is a non-hierarchial taxonomy, we could also rename 'Standard' to 'No post format' and it would be a waste to add such a term to each post, as far as I understand it.
    – birgire
    Commented Feb 8, 2015 at 10:37

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.