get_pages fails with Pods installed
-
I’m using two Custom Post Types (Event and Event Item). An Event can have multiple Event Items. Before discovering Pods I was using the post_parent in the Event Item CPT for the many-to-one relationship.
get_children()andwp_get_post_parent_id()fetched the relevant CPTs to display in the Theme.I establish the Event CPT’s ID in Event ID, I used the following:
add_action('add_meta_boxes', function() { add_meta_box('event', '<h1 style="color:red;">Choose An Event For This Item</h1>', 'event_meta_box', 'event_item', 'side', 'high'); }); function event_meta_box($post) { $pages = wp_dropdown_pages(array('post_type' => 'event', 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('SELECT EVENT'), 'sort_column'=> 'post_title', 'echo' => 0)); if ( ! empty($pages) ) { echo $pages; }This creates a metabox in the Event Item with a dropdown of the Events.
However, this previously-working code stopped working with Pods installed. The metabox appears in the Admin UI but the dropbox with Events does not. I added this:
// test get_pages $checkpages = get_pages (array('post_type' => 'event'));With Pods installed
wp_dropdown_pagesreturns a empty string andget_pagesreturns false. It works as soon as Pods is uninstalled.Yes, I know the Pods Way is to use a Relationship field (podsrel table) and that’s what I’ll do. I’m just curious why this stops working.
-
Hello @johnbuol
I’m actually not sure why Pods would interfere with
get_pages. Did you register theeventpost type through Pods as well? If so, did you correctly set the public and queryable options?Cheers, Jory
>> Did you register the event post type through Pods as well?
Yes.
>> If so, did you correctly set the public and queryable options?
No, and that was the fix. Looking back at my old plugin and then re-reviewing Pods settings, I see what I failed to do.
The Metabox works now. Thanks! Pods is really great, especially when I stop overlooking things 🙂
-
This reply was modified 5 years, 10 months ago by
johnbuol.
No problem!
Cheers, Jory
-
This reply was modified 5 years, 10 months ago by
The topic ‘get_pages fails with Pods installed’ is closed to new replies.