Get a Free Quote

We respect your privacy

Sorting Custom Posts by Custom Fields in WordPress

8:03 am

Sorting Custom Posts by Custom Fields in WordPress

WordPress is open source software with many different implementations. In addition to which it also allows several levels of customization. When you hear the word customization it is common for you to think in terms of hiring a Professional WordPress Web Developer like Alakmalak.

In fact Alakmalak is fully capable of helping you out with your customizations in WordPress but we digress. WordPress is quite modular, hence it is possible achieve your goal by making a few minor changes to programming code.

There is also a nice editor provided and with the instructions mentioned here it becomes quite easy for even a person with less or no programming experience to make changes.

WordPress allows many different levels of customizations and also allows you to sort posts by custom fields as described below:-

1. The first thing you will need to do is to login to the admin section of your WordPress installation.

2. Navigate to the admin menu Appearance >> Editor

Go to the menu Appearance -> Editor

3. Here there will be a list of files that are used by your current template.

4. We will assume that you have a portfolio page are using a page template called Filterable 3 cols page. The fact of the matter is that you could be using any page and any template depending on the template that you have installed.

5. You can click on the template mentioned above (or your own template file in your case) and this will open up the programming code for you to edit this tile. This code is mainly PHP code.

6. There is an alternative to doing this as well. You can prefer to use FTP. If you do choose to use FTP all you need to do is connect to your server using FTP first. Then navigate to your theme directory and download the template file. And once you do make the changes mentioned below using your favourite editor you can simply upload it back to your server.

7. Once you do have the file open either online or after having downloaded it you need to look for the following line:


8. Here you need to add
meta_key=order1&orderby=meta_value_num&order=ASC to make the programming code look like below:
$wp_query->query(“post_type=portfolio&paged=”.$paged.’&meta_key=order1&orderby=meta_value_num&order=ASC&showposts=’.$items_count4); here order1 is the name of your custom field.

9. Now either update the file using the update button in case you are editing online or else upload the file using FTP if you have downloaded it and have edited in your editor.

10. This custom field needs to be added to the post you’re using on a particular page. Thus since we have taken the example of portfolio here; we need to open the portfolio post and select the post you want to appear first.

11. While on the post page, search for the custom field block usually located to the bottom of the page. Additionally if you cannot find it, it means it is hidden. You will then need to hit the ‘Screen Options’ button and check the ‘Custom Fields’ box to view it.

12. Here you need to add your new custom field by clicking on the ‘Add New Custom Field‘ button. Enter the name of the custom field; we have chosen the name ‘order1′ in this example and hence we will still with that.

13. You also need to enter the value here. In order to make the post appear first you should enter ‘1’ or if your want it to appear on 5th position or example then enter ‘5’.

14. Update the post from the right column and save your settings.

15. This will sort your posts as per the order you have selected.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Comments are closed.