I have an options page for my plugin, but cannot seem to figure out how to create an option to allow admins to select a page that will display my plugins content.
Does anyone have an example of how this is done?
EDIT:
I created a plugin and have a widget to search the content of my plugin. However I need the widget to post to the page that my plugins content is being displayed on. Since the widget is on the sidebar it could be submitted from any page, I need to be able to detect which page the plugin content is being displayed on and se the to that page.
1. detect the shortcode on a given page, and use that.
OR
2. Create an option from a settings page to allow the admin to select which page the plugin content will be displayed on and get rid of the shortcode.
I hope that clarifies.
I have a settings page for my plugin, I just do not understand how to get a list of the available pages and save/update the option in the wp_options table.
Here’s a quick options page that will give you a dropdown select for choosing a page, using the
get_pages
function. The Settings API takes care of saving the options for you. You can then useget_option
to load the options array in your template, andget_post
to load the post data associated with the ID saved in your option.Rather than reimplement the dropdown as @Milo suggested, it’s easier to use
–as described at https://developer.wordpress.org/reference/functions/wp_dropdown_pages/