The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Getting pages of a site into a dropdown, can this be done dynamically?


This Discussion is public


I am trying to create a system where an admin or editor can create a page from the front end... this is relatively easy. It's the next part that I have questions about. I'd like the user to be able to select a page that exists in the site from a drop down as the parent page and have the new page listed as a child when published. I am creating a note taking system in which the user can take notes, I'd like that to be associated in the hierarchy by selecting the parent page... any way to do this? I really appreciate any help with this, and thanks in advance.

I think it depends on how familiar you are with the WordPress database structure.

On the Formidable side of things, you can hook into frm_setup_new_fields_vars and frm_setup_edit_fields_vars to create a dynamically populated dropdown. Here's a tutorial that explains how:

The code displayed in that tutorial is very basic, and should be used as an example.

On the WordPress side, all page header information is stored in wp_posts with a post_type of "page". In a hierarchical setup, the post_parent field is populated with the id of the parent page. If the page has no child pages, the post_parent field is 0.

Assuming you want a user to add child pages to their own parents, you also have to query the post_author field which means you need the author's user id as well.

You'll have to construct your own SQL query to get the data you want to display. When I have a requirement like this, I usually write and test the SQL first in PHPMyAdmin, then take the working SQL query and rewrite it so it works in PHP using $wpdb variables like table prefix, etc.

As a guideline, this is probably a 1-2 hour job. It can take some tweaking to get the SQL query right.

Wow, that was so helpful and well written. Thank you for this response vfontjr :), I'll let you know how I made out!

Discussion closed.