Customize any wordpress, add new custom post type, meta query, lookup

back to snippest | Comment | Share

Customize any WordPress, add new custom post type, meta query, lookup

in order to customize any WordPress theme you need to have a wordpress installation and two plugins, for the first part we recommend greenbackend wordpress solution which will handle any WordPress website with all the different needs and capabilities, we recommend the Unlimited and Business Geko Pro wordpress hosting, you could check them here http://greenbackend.com/wordpress-hosting

Additionally, We need the following two plugins to manage the database and the UI:
1-Custom Post Type UI By WebDevStudios – link
2-Advanced Custom Fields By Elliot Condon – link

These two plugins are used to create new entities such as database tables and fields or columns, since WordPress is an EAV framework it uses WordPress tables and meta table to create the tables and the columns.

In this scenario, We will create a program table ” in WordPress we call it a program custom post type“.

1-program custom post type

2- After saving the program custom post type you will see it under the main menu with the given cpt properties

3- We need to add extra columns to the program post type

Logo – Image Field, it got Image URL in its return format
ٍSummary – Text Area
Gallery – Post object to load a woo commerce product and its images, Filter used is Product, return format is Post Object
facebook – Text Field, to store social profile link

Note: Its important to map the current field to be within the Location of Program, so Post type shoud be “is equal to” “Program” inside the Location Rules.

4- Save the field and open new or edit program screen you will see the following, just assign the product and different items to the program and you are done

In the previous links we’ve seen how to link program with other objects such as product, such that each program might have a product item, but some times a program might have many news, many events or activities, in this case we need to link the news item or event item with the program it self, this relation is called 1 to many whereas the program to product relation is called one to one.

5- in order to create the one to many relationship in WordPress we have to navigate to many and add it to one like the following:

The same rule applied for the events.

6- Link many to one, simply navigate to any post and link it with the program field and you are done.

You did a great job in the previous steps, now its time to make a page inside the theme and display the related fields, we will leave you a code snippets from the program template inside the theme:

1- Create a file named – single-program.php

2- Insert the following script to view the program

Note: You might have noticed that we used “icl_t” which indicates that we’ve used a translatable WordPress strings, you could checkout in this link here a complete example how to use localizable strings within WordPress and wpml.

Wow, you did it, if you feel this lesson was helpful give us a message thru whats-app www.wtsb.me also you could give us a donation on Paypal at usd.paypal@greenbackend.com if you wish to see more free posts like these in the future.

Thanks for viewing this! <3 -Ahmad Naser

About the Author

Hi! I'm Ahmad. I have a degree in Computer Science from Birzeit University and you might call me a bit of computer geek. I am the Founder of Greenbackend Turnkey Solutions a leading Cloud and Hosting Company in the Middle East, Also I am the Founder of Ahmad Naser Turnkey Solutions in Harvey, LA, USA. I'm comfortable with a large range of languages and techniques. After implementing enterprise applications using Salesforce and Siebel CRM for 3 years and with professional experience in building websites, cloud apps, iOS apps, Unity games, Android mobile apps and educational games for 8 years. I decided to share my technical knowledge with people all over the world to benefit from my experience and build their own careers specially because I am a real world example with over 20 successful apps on Google Play Store, Asset Store and Apple Store, So your success is mine and I want to help you reach your goals step by step exactly as I do. I'm passionate about teaching people about technologies, so from time to time I gave courses online and in learning centers and teach beginners and professionals on many technologies and development frameworks. One of my greatest goals in life is growing the next generation of software professionals and to keep teaching programming at every opportunity I get. I can't wait to help you experience the achievement and financial freedom that having a deep understanding of technology brings. So why not start learning to design & develop now by joining our epic Unity 3D professional 2d game development course? See you soon! Ahmad

>