For Such Interesting articles
How to Sort Custom Posts By Custom Field 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
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.
Why Choose Alakmalak As a Your Growth Partner?
Alakmalak is a Web Development Company In India that offers services for several technologies. There have been around for a very long time and have developed over 2500 projects for clients all around the world. They have highly skilled web developers with a great deal of experience.
- how to add custom fields in wordpress
- How to sort custom posts by custom field?
What’s Next ?
I know after reading such an interesting article you will be waiting for more. Here are the best opportunities waiting for you.
Uncover our captivating services
Supercharge your business with us
OVER 600 Small, Medium and Large Enterprise business clients have chosen us from 35 COUNTRIES
I want to thank all Alakmalak team for take my project and help me to improve my website! Thank you for your responsibility and seriousness at the time to do corrections and improvements on my website and for always be in touch with me. Highly recommended! Great team! Great company! I'm very thankful Alakmalak!
Frank M. Cali.USA
A few kinds words to say about Alakmalak programming and design. Working with these guys is always such a great relief. You know you are getting your stuff done right and usually always in a timely fashion. I’m a middle man for the most part And my clients are always happy with the end result.