Fixing the get_posts() Query for Custom Post Types

A white, rounded square logo with an abstract S-shaped design on a gradient blue and purple background.

As we start to develop larger  WordPress® sites, one thing becomes apparent: backend organization can become very confusing for clients.

At PaperStreet Web Design, we have come up with a solution that deals with a combination of two WordPress® Plugins.  The two plugins are Custom Post Types UI and Advanced Custom Fields.

The combination of these two plugins will allow you to create custom post types in the WordPress® Dashboard area, then customize them to be specific to your page layouts.  As a law firm web design studio the most common scenario when we would use this method would be to separate general pages, blog posts, practice areas and attorney profiles.

Previously, we would have just added all the Practice areas, Attorneys, etc., under Pages in the WordPress® Dashboard area.  However, this can get very confusing if you have 100 Attorneys, 100 Practice areas and even more pages.

Creating one Custom Post Type for Attorneys and one for Practice Areas can separate the content greatly for the client, allowing them to have a very organized, clean backend WordPress® Dashboard area to edit their site with.

Common Issue for Custom Post Types and the get_posts() Query

However, a common issue we have run into while working with these plugins is using the get_posts() WordPress® function.

Typically, we could pass in a value such as:
‘post_type’ => ‘attorneys’

This should work.  However – if it does not – what can you do?

Solve the get_posts() function not working for custom post type problem in 1 simple step.

The problem is not your code!  In the WordPress® Dashboard area go to Custom Post Types > Manage Custom Post Types, then select ‘Edit’ for the particular Post Type you are having issues with.  Open up the ‘Advanced Options’ on the left side.  Scroll down to where it says ‘Hierarchical’ and select ‘True’.

enable_hierarchical

Once ‘True’ is selected for Hierarchical, your get_posts() query for the custom post type should now work properly.

It is important to know how to fix these minor issues because these are the foundations for a well-organized law firm website.  Separating the templates into custom post types will allow the client  to feel accomplished when they log into the Dashboard area, as everything becomes more intuitive.

If you are interested in working with PaperStreet on a law firm website please contact us today for a free evaluation and consultation.

Share This
Blog Decorative Background

Join the Sales and Marketing News, receive our last insights, tips and best practices.

Our 7 Guarantees

Keeping 2,000+ Clients Happy Since 2001.

1
You Will Love Your Design We design to please you and your clients
2
Same-Day Support 24-hour turnaround edits during business hours
3
Free Education We provide knowledge to help you expand
4
No Hidden Charges We quote flat-rate projects
5
Own Your Site No strings attached
6
We Create Results SEO, PPC, content + design = clients
7
We Make Life Easier One agency for web, branding and marketing