I admit, I still think in Drupal. (In choosing between developing in WordPress and Drupal, I still tend to favor Drupal, because I haven't yet figured out a few things on the WordPress side.)

Can you help to figure out how to achieve in WordPress at least some of the Views functionality I know and love?

I can see that plugins that work with Custom Post Types are the WordPress equivalent of CCK. Now, is there a way (either through a UI or code) to: 1. display custom fields in columns and rows 2. Expose filters, that is, create drop-downs at the top, to allow the end user to select

Here's a sample image of a single exposed field. http://www.packtpub.com/sites/default/files/Article-Images/drupalviews-article1-timage18.png (from my book)

Variations would include filtering by more than one topic or custom field, being able to select multiple options, selecting on fields that are not just categories or tags, etc.

There's one argument to be made that if I like Drupal so much, I should use it. But I think I could be a happy WordPress user too, if I could figure out how to display custom fields,and how to allow end-users to select through exposed filters. Any guidance welcome.


I'm studiously working my way through two answers so far. And so far I've been able to create custom fields, and display them, one post at a time.

This is what I've added to my single.php. (It's somewhat messy, and I welcome ideas for improvement.) But what I still have to do is get this out of the single.php context, so that I can display ALL post fields, and not just the current ID. (Also, my current css yields .meta_items displaying under the wrong .meta_table_header if there are blank fields. Seems setting the width doesn't work if the element is empty, so somehow I have to populate it with a nobreak-space.)

I also installed the Custom Field Template plugin: http://wordpress.org/extend/plugins/custom-field-template/, and figured out how to comma-delimit the results of multiple checkbox selections. (I haven't played much with Custom field Template yet, but I have the feeling I'm going to like it.)

 <div id="meta_table">
  $div_meta_row =  '<div class=\'row\'>';
  $div_meta_item ='<div class=\'meta_item\'> ';
  $div_meta_table_header='<div class =\'meta_table_header\'>';

   echo $div_meta_row;
   echo $div_meta_table_header, "Breakfast", $div_end, $div_meta_table_header, "Currently Reading", $div_end, $div_meta_table_header, "Hours of Sleep", $div_end, $div_meta_table_header,'Favorite Fruits', $div_end;
   echo $div_end;

   echo $div_meta_row;
      $meta_values = get_post_meta($post->ID, 'Breakfast', $single);
      echo  $div_meta_item, $meta_values, $div_end;
      $meta_values = get_post_meta($post->ID, 'Currently Reading', $single); 
      echo $div_meta_item, $meta_values, $div_end;
      $meta_values = get_post_meta($post->ID, 'Hours of Sleep', $single);
      echo $div_meta_item, $meta_values, $div_end;
      $meta_values=implode(get_post_meta($post->ID, 'Favorite Fruits', 0), ', ');
      echo $div_meta_item, $meta_values, $div_end;
    echo $div_end;

Here's the accompanying style sheet, which I placed in header.php.

<style type="text/css">
#meta_table .row {
margin:10px 0;
#meta_table .row .meta_item, .meta_table_header {
.meta_table_header {

Once I get all the posts' fields to display in a separate URL, I'll work on the "custom fields parameters of query_posts." So, I know more than I did when I first asked the question. Still a ways to go.

(Drupal Views offers a powerful UI, and so far this is almost all coding, but I'll wait until I truly have this figured out in WordPress before making any pronouncements about which is easier. I'm hoping in the end to enable the user to filter by multiple custom fields in WordPress.

Here's what this looks like so far.

Progress so far...

Aiming for something more like:


  • Reading up on the Drupal Views module, it sounds like it's just a visual (i.e. drop-down) query builder. Is that correct? If not ... what functionality are you trying to create? When I see the word "view" I think in terms of design and presentation ... but reading the Views module page it sounds a lot more like business logic and data access ... can you clarify for the non-Drupal users on the site?
    – EAMann
    Oct 4, 2010 at 15:38
  • Views is, indeed, a query builder. (Note that since "Views" is the name of a module, I'm using the singular.) One of the component modules is views_ui, the user interface for building (lower case) views. I'm not asking how to create a UI for query-building in WordPress. (It would be wonderful to have one, but what I'm trying to do is more basic). I'm simply trying to get some of the core functionality of the module, namely: displaying custom fields, and enabling end users to filter the display of fields by one or more custom fields, using dropdowns. Here's another example: bit.ly/aSBqrt Oct 4, 2010 at 17:11
  • From the looks of things, you might be better served using custom taxonomies (rather than custom meta fields) and having each dropdown list populate with the available items in that taxonomy. You'll lose freeform entries (like hours of sleep in your example), but the support for listing/sorting based on a taxonomy is far superior to that of custom meta.
    – EAMann
    Oct 4, 2010 at 17:32
  • Thanks for that comment/idea. When you say custom taxonomies do you mean categories and/or tags, or do you mean something else? Where do I start? Oct 6, 2010 at 12:05
  • Tags/Categories are taxonomies, but you can also create your own custom taxonomy systems. Here's a great tutorial that demonstrates using custom taxonomies to build a movie database. There's also more information in the Codex.
    – EAMann
    Oct 6, 2010 at 15:49

5 Answers 5

  1. display custom fields in columns and rows: get_post_meta to display them in your theme, and add_meta_box to customize the admin

  2. Expose filters, that is, create drop-downs at the top, to allow the end user to select: you may want to use the custom fields parameters of query_posts. E.g.:

Dropdown field in a form at the top:

<select name="custom_field" id="custom_field">
    <option value="value1">Value 1</option>
    <option value="value2">Value 2</option>

Corresponding custom query:

$value = $_POST['custom_field'];

You may want to see The Loop and get_posts for reference.

Hope this helps.


lol, i think you still need to invest more on wordpress codex function: get_post_meta check this on wordpress codex site and you'll see all you want. and to build your CCK like custom fields, use More Fields plugins and create your own Custom Fields and type there and then assign it to your custom post type and set the role for it. honestly after alot of work with wordpress i can tell you, you can do anything with wordpress, there is no limitation. You will see more polish version soon by releasing of wp3.1 Query multiple taxonomies, custom post type archive template and so on.

  • That's a very helpful start. Now for part 2 of the question: how to get a dropdown filter above all the posts, or more than one dropdown so that end-users can use multiple custom fields to limit the "view?" BTW, my new favorite site (apart from this one) is phprex.com. For instance, here's the function definition for get_post_meta: phpxref.com/xref/wordpress/wp-includes/… A quick hyperlink from there to get_metadata shows exactly what's going on. Now I'll be able to display custom fields. But what about the "exposed filters" piece? (filter dropdowns) Oct 1, 2010 at 22:27

Shameless self promotion:

My plugin attempts to emulate Views 2 UI for building custom queries very closely.

This plugin lets you create new WP queries as pages or widgets. It's basically Drupal Views for WordPress.


Hope to liven up this thread a little - as it seems like an excellent idea. I've been a Drupal user for a little over a year and find Views invaluable on a daily basis. You may want to check out a WordPress plugin I found - Views for WordPress - but this doesn't allow front-end filtering/sorting (just admin) - so definitely something to build on. To be able to expose these filters/sorting options selectively to a user would be extremely beneficial. Thanks!


There is also thisWP module that offers some of the Views functionality: http://wordpress.org/extend/plugins/query-wrangler/

  • 1
    Can you at least explain what Views functionality it provides?
    – s_ha_dum
    May 10, 2013 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.