Black Friday & Cyber Monday sale, save 30%! Valid until November 30th at 11:59:59 PM (UTC - 6). Enter BFCM2015 at checkout or Click here to apply discount →

Several users have requested that I build a “rating” field type for Easy Content Types that will allow administrators / editors to apply a rating to a post or custom post type entry. This sort of field type would be exceptionally useful for users running review websites, such as book, movie, or game reviews. I have gone ahead and built a simple star/number rating field type, and would like to share with all of you the methods used to build such a field type. It is a little complicated, but if you’re already familiar with adding new field types in Easy Content Types, you won’t have any problems.

If you have not already watched my tutorial on how to register custom meta field types in the plugin, then go watch it now.

The field types we will be creating look like this:

When rendered on the front end, our fields will look like this (when using the automatic display meta function):

In the video, I walk you through all of the functions (except the last two; the reason is explained in the video) and describe the process of setting up the new field type. To aide you in building your own rating field type, the complete code is below:

You must be logged in and have an active premium membership to view the rest of this content. Register or login from the sidebar.

Join now to gain access to this tutorial and more.

Join Now
  1. rsmelik


    This tutorial is awesome! I had asked you for some sort of integration of this feature back when I bought ECPT but haven’t gotten around to diving into the tutorial until now! I personally liked how you worked through some of the the issues with the code. It got me thinking in a new way. I am not a PHP expert so I am picking up this stuff as I go along and it good to see the problem solving side of things.

    So I know you mentioned that if I wanted a short code I needed to add that as a new short code function but what about if I wanted to hard code this into my template. I am able to see the script in action, using the auto display function in my ” Books” post type (visible at the end of the post) but I haven’t yet been able to figure out the correct equation for the PHP string that I need to add to my template file. The usual doesn’t seem to populate the right data. It is returning the number rating instead of the star rating. You can see what I am talking about on this page:

    The rating below the content is correct and was added via the automatic feature in ECPT but the rating above the bookshelf was my attempt at hard coding the query into my template file. Unfortunately it didn’t return the correct data.

    Any thoughts/suggestions?

    Thanks! – Rob

    • Pippin

      Is that page using the short code? Also, is it using the number or the star rating?

  2. samasmar

    Hey Pippin, thanks for your great plugins tutorial. I’ve found an issue when trying to display star ratings with shortcodes.

    These both displays the rating in a number format. However if I do it from the ecpt settings by activating “Check this box to automatically display meta box field values after the item content for the post type” it works perfectly. Please advise. Thanks

    • Pippin

      Sam, this tutorial simply showed how to make the fields, and displaying them via short codes was not included. You will have to extend the code to do that.

Your email address will not be published. Required fields are marked *

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match