This plugin provides a shortcode that displays a list of posts with a certain custom field. Since you can supply multiple custom fields you’re able to aggregate posts with different custom fields. Furthermore you can easily change the sort order.
You can download the plugin here.
Once you’ve installed the plugin you can use the shortcode
lp for short) to display posts. Say, if you wanted to get all posts with the custom field
howto you would enter this into the content of a post/page:
This results in a list of posts with the given custom field.
You can use the following attributes in the shortcode.
- You can supply the custom field here. If you’d like to use multiple custom fields just separate them with a comma.
- By default the posts will be ordered by their publication date. If you’d like to order them by their title you would use
post_title. Look at the fields of the
wp_poststable and pick whatever you like. Ordering by the value of a custom field is possible too: just use
cfvalue:fieldhere and replace
fieldwith the real key of the custom field that should be used during the sorting algorithm.
- Either use
DESCfor ascending or descending order respectively.
- The plugin uses the standard title of a post to display the title but may use a custom field instead. This comes in handy if you want to display another title for a post in the list generated by this plugin without chaning the post’s original title.
- Again, this field lets you choose a custom field which will be used instead of the post’s excerpt. Say, you’re using the All in one SEO plugin which stores the meta description in a custom field called
descriptionyou may use its value instead of the standard excerpt.
- The title that’s displayed can have a custom prefix or suffix. The constant
%PERMALINK%will be replaced with the permalink of the current post or page.
- You can specify a custom prefix or suffix for the excerpt as well.
- In case you specified a custom field via the attribute
fieldthat may be attached multiple times to a single post or page you can split the results by turning on this attribute, e.g. with
split=1. This way the output may contain a post or a page several times.
- You can make sure that the results will be associated with the given categories. Just supply a comma separated list of category IDs.
- This attribute helps you displaying posts that have a given custom field set to a specific value. It’s a great way to display all posts having a certain custom field and another one with a particular value. Say, you only want to display posts having a field
blahwith its value set to
123you would use
having=blah,123in the shortcode; see that by default a comma is used to separate the value from the field’s name, multiple fields are separated with a semicolon.
- In case your custom field contains the default delimiter that is either used to separate the key from the value or multiple custom fields from each other in the having clause you can change the delimiters. This would be an example to get all the posts having a field
testset to either
[lp field=test having="test;xxx|test;xxx,yyy" having_delim=";" having_delim2="|"]. Due to the fact that the value
xxx,yyycontains the standard delimiter “,” I used a “;” instead.
Defaults are as follows:
having_delim= “,” and
- You can switch between
oras the conjunction of multiple fields in the having clause; default is
or. This way either all or just at least one field with it’s key / value combination needs to be present to add the post to the result set.
- Helps you to limit the amount of displayed elements. If you’ve got five posts with a particular custom field but only want to show the first three you’d use
I’ve created separate pages for all my WordPress plugins. All of them have a custom field called
wordpress. The following shortcode was used to produce the list as you can see it here:
[lp field=wordpress orderby="post_title" order="desc"]
If I create a new page for a plugin I just have to annotate it with
wordpress and the list will display it automatically. Neat, isn’t it?