wordpress - Dropdown of existing posts in a metabox -
I have the ability to select one page, which should appear in a sidebar, from multiple post types. So I understand that I need a meta box with a dropdown list of all the positions, but I do not know how to create it in the function.
All I want is exactly the same, but this does not help me much, because I can only select from a post type and can display in the post pages.
is a free plugin that will solve all your troubles. It says. It has the ability to add a list of posts to a field and attach that field to pages. Here's how you would do it:
First install the plug-in and navigate to the custom field screen. Fix your area like this:
< P> Then you need to select these options in the options given below that section:
This will play ACF only on pages. After setting up you will get a small sidebar block like this:
You can then select each post for the page and it will return that object to the frontend. To impose the required positions for you, you need to use a little code to get the frontend. Here's the code to get the frontend option from ACF. I need to add this code within the sidebar.php
file:
Global $ post; // Global Post Object $ sidebar_posts = get_field ('post', $ post- & gt; id); // Receive field using postal mail foreach ($ sidebar_posts $ sidebar_post) {// $ sidebar_post-> via loop post Post_title; // Post Title Entity}
This will only loop through the posts you select and echo the title. You can do more by adding some other Wordpress post functions using it. This will allow you to do things like the_title ()
and the_content ()
.
Hope it helps!
Comments
Post a Comment