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.
Howto
Once you’ve installed the plugin you can use the shortcode list-posts (or 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:
[lp field=howto]
This results in a list of posts with the given custom field.
Attributes
You can use the following attributes in the shortcode.
field- You can supply the custom field here. If you’d like to use multiple custom fields just separate them with a comma.
orderby- 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 thewp_poststable and pick whatever you like. order- Either use
ASCorDESCfor ascending or descending order respectively. titlefield- 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.
excerptfield- 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. having- 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 to123you would usehaving=blah,123in the shortcode; see that a comma is used to separate the value from the field’s name. limit- 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
limit=3.
Examples
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?
15 comments ↓
My custom field is author and I use it to store the author of the article.
Thomas
the plugin doesn’t support this because it had to look at the content of the custom field and compare it to some pre-defined value. Of course, you could adapt to plugin to do this but I think you’re better off using the function
wp_list_pagesalong with the parameterauthors.ich wollte dein plugin installieren, um gewisse beiträge auf einer statischen seite anzuzeigen und eventuell mit einer anderen überschrift zu versehen.
leider war ich nicht erfolgreich. ich habe dem gewünschten beitrag ein benutzerdefiniertes feld hinzugefügt (schlüssel=field, wert=rezept). auf meiner statischen seite im editor [lp field=rezept orderby="post_title" order="desc"] eingegeben, aber leider ohne erfolg.
ich bin nicht besonders versiert, also vielleicht mache ich wo einen fehler. hast du ihn entdeckt?
im prinzip würde ich genauso, wie du auf deiner pluginsseite eine bebschriebene liste erstellen wollen. hoffentlich klappt es mal.
danke dir und grüsse
horst
bin schon eine spur weiter: der wert schlüssel muss den field wert enthalten (also z.b rezept).
wie kann ich aber die beiden felder excerptfield und titlefield anzeigen und auslesen lassen?
danke und grüsse horst
now I can order by post_title (i.e.) but I would order by a value of a particular custom field too.
tnx
this is on my todo list and I’ll add it to the plugin in a future version.
ie; the plugin will look for all posts with a custom field of Blah.
I want it to list only posts where Blah = 123 (for example)
Is that possible? I assume it’s just a modification to the code, but I can’t figure out where.
search for the first
foreachin the plugin’s file. Inside this loop you’ll have to add code like the following:This should make sure that only posts having a custom field “Blah” set to “123″ will be displayed.
Update: This can be done with the
havingattribute now.Thanks!
I’ve added another attribute: use e.g.
limit=5to do just that.I’ve just tried using the plugin and it basically adds all custom fields from the specific field not just the ones with the value I specified.
When I upgraded to WordPress 2.9.1 from 2.8.x, the page changed to a list of “Array” strings. Instead of the post title, the string “Array” would be there.
# set correct title/excerpt
#for ($i = 0, $n = count($result); $i title = lpcf_get_custom_field($post->ID, $titlefields, $post->title);
# $result[$i]->excerpt = lpcf_get_custom_field($post->ID, $excerptfields, $post->excerpt);
#}
thank you for the feedback. I’m looking forward to fix the plugin.
Leave a Comment