Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Filtering by Post Format #113

Open
alexstandiford opened this issue Sep 13, 2024 · 0 comments
Open

Enable Filtering by Post Format #113

alexstandiford opened this issue Sep 13, 2024 · 0 comments
Labels
Enhancement New enhancement or feature request.

Comments

@alexstandiford
Copy link

What problem does this address?

Hello there! Huge fan of this plugin - it's rapidly becoming one of my go-to tools for building sites these days.

I use my website as a central hub, which means that I post everything on there, including tweets, blog posts, and externally written content that backlinks to the original posts.

This means that I need to display content differently based on the post format, particularly when I'm working with a query loop block, and want to show micro posts so that they look like "tweets", sharing the full post content, and then blog posts as a more traditional post with a featured image and excerpt.

Post Formats is a theme feature introduced with Version 3.1. A Post Format is a piece of meta information that can be used by a theme to customize its presentation of a post. The Post Formats feature provides a standardized list of formats that are available to all themes that support the feature. Themes are not required to support every format on the list. New formats cannot be introduced by themes or even plugins. The standardization of this list provides both compatibility between numerous themes and an avenue for external blogging tools to access this feature in a consistent fashion.

image

I'm able to accomplish this using this plugin by filtering post content based on the post format:
image

The Problem

The problem is that this plugin doesn't support filtering by post format. I have found a workaround that allows me to filter based on post meta, using a filter, but it would be nice to be able to directly filter by post formats, if they're supported in the theme.

<?php
/*
Plugin Name: Post Format As Post Meta
Description: Adds a hook that makes it possible to access the current post 
*/

add_filter('get_post_metadata', function ($value, $post_id, $meta_key, $single) {
	if ('_as_post_format' === $meta_key) {
		// Get the post format for the post
		$post_format = get_post_format($post_id);
		if ($post_format) {
			return $post_format;
		} else {
			return 'standard';
		}
	}

	return $value;
}, 10, 4);

What is your proposed solution?

It would be nice if:

  1. Post filtering could be done based on the value of the post format function in WordPress. This can be done using get_post_format.
  2. Filtering would be enabled if the theme supports any post formats, and formats could be selected from the list of formats that are supported by the theme, eg: get_theme_support('post-formats')

By doing this, I would no-longer need to use the meta key hack I mentioned above, and could instead directly filter based on the post format.

@ndiego ndiego added the Enhancement New enhancement or feature request. label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New enhancement or feature request.
Projects
None yet
Development

No branches or pull requests

2 participants