get_children()
and wp_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_pages
returns a empty string and get_pages
returns 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.
]]>This is what I have now:
<form action="<?php bloginfo('url'); ?>" method="get">
<?php $select = wp_dropdown_pages( array('post_type' => 'page', 'show_option_none' => '— Select —', 'child_of' => 6, 'sort_column' => 'post_title') ); echo str_replace('<select ', '<select onchange="this.form.submit()" ', $select); ?>
</form>
]]>I’ve built a slider plugin using custom post types. My goal is to be able specify the page URL in the custom post type and then be able to use it later in a public function widget to populate a unique link in each slide.
I’ve got the metabox to populate a dropdown of all pages using wp_dropdown_pages with no issues. I’m struggling with getting the selection to save and then retrieving the selected URL to be used later.
My PHP is pretty shaky at best but I’m eager to learn. I’ve read several Codex entries including ones on both wp_dropdown_pages and metaboxes but haven’t been able work out a solution. If any of you have any suggestions or can point in the direction of some additional reading that my be of assistance I’d be grateful!
This is what I’ve come up with:
add_action( 'add_meta_boxes', 'carousel_tabs_url' );
//Output of metabox content
function carousel_tabs_url_callback( $post ) {
$dropdown_args = array(
'post_type' => 'page',
'name' => 'myplugin[page]',
'sort_column' => 'menu_order, post_title',
'echo' => 1,
);
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename');
//Dropdown of pages
wp_dropdown_pages( $dropdown_args );
}
//Save wp_dropdown_pages
function carousel_tabs_url_save( $post_id )
{
// Check save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'my_custom_nonce' ] ) && wp_verify_nonce( $_POST[ 'my_custom_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exit script depending on save status
if ($is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Check for input and sanitizes/save if needed
if ( isset( $_POST[ 'meta_key' ] ) ) {
update_post_meta( $post_id, 'meta_key', $_POST[ 'meta_key' ] );
}
}
//fire save action
add_action( 'save_post', 'carousel_tabs_url_save' );
//loads saved URL into var
$carousel_tab_url=$_POST['myplugin']['page'];
]]>wp_dropdown_pages($args);
$args = array(
'name' => 'registered_setting',
'selected' => get_option('registered_setting')
);
]]><?php
/*
Plugin Name: Mardit's Featured Page Plugin
Plugin URI: https://mardit.com/plugins/mardit_featured_page.php
Description: This plugin will allow a user to choose a page to display in a featured page widget with a customizable learn more button and excerpt.
Version: 1.0
Author: Mario Keeney-Ditolla
Author URI: https://mardit.com
License:
*/
class mardit_featured_page_plugin extends WP_Widget {
// constructor
function __construct(){
parent::__construct(
'mardit_featured_page_plugin',
__('Mardit Featured Page', 'text_domain'),
array( 'description' => __('Mardit Featured Page Plugin', 'text_domain'),));
}
// display widget
function widget($args, $instance) {
// these are the widget options
$title = apply_filters('widget_title', $instance['title']);
$page_id = $instance['page_id'];
echo $args['before_widget'];
// Display the widget
echo '<div class="widget-text wp_widget_plugin_box">';
// Check if title is set
if ( $title ) {
echo $args['before_title'] . 'Featured Page' . $args['after_title'];
}
// Check if text is set
echo $instance['page_id'];
echo '</div>';
echo $args['after_widget'];
}
// widget form creation
function form($instance) {
// Check values
if( $instance) {
$title = esc_attr($instance['title']);
$page_id = esc_attr($instance['page_id']);
} else {
$title = '';
$page_id = '';
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('page_id');?>"><?php _e('Page ID');?></label>
<?php wp_dropdown_pages(array(
'id' => 'page_id',
'name' => $this->get_field_name('page_id'),
'selected' => $instance['page_id'],
));?>
</p>
<?php
}//end form
// widget update
function update($new_instance, $old_instance) {
$instance = array();
//fields
$instance['title'] = strip_tags($new_instance['title']);
$instance['page_id'] = strip_tags($new_instance['page_id']);
return instance;
}//end update
}//end class
// register widget
function register_mardit_widget() {
register_widget('mardit_featured_page_plugin');
}
add_action('widgets_init', create_function('', 'return register_widget("mardit_featured_page_plugin");'));
?>
]]>I’m using wp dropdown pages to show side navigation for responsive site.
I’m using child_of to show all the pages of within the current section of the site. The problem is I can’t figure out how to include the parent page in the drop down as well as the child pages.
Any ideas?
Cheers
]]>Specifically. I would like to use the “Page-list” plugin or the “WP Dropdown” plugin to use shortcode to insert a few different lists of posts, each listing subpages with a certain tag.
Any thoughts or help is appreciated.
Chris
]]>So
<select >
<option class="level-0" value="2">Home</option>
<option class="level-0" value="8">Praktisch</option>
<option class="level-1" value="53"> Contact & Route</option>
<option class="level-1" value="55"> Mission</option>
<option class="level-1" value="57"> Who is who</option>
<option class="level-0" value="12">Schrijfcoaching</option>
<option class="level-1" value="63"> Schrijfcoaching</option>
<option class="level-1" value="65"> Manuscriptbeoordeling</option>
</select>
should be
<select >
<option class="level-0" value="2" disabled>Home</option>
<option class="level-0" value="8">Praktisch</option>
<option class="level-1" value="53"> Contact & Route</option>
<option class="level-1" value="55"> Mission</option>
<option class="level-1" value="57"> Who is who</option>
<option class="level-0" value="12" disabled>Schrijfcoaching</option>
<option class="level-1" value="63"> Schrijfcoaching</option>
<option class="level-1" value="65"> Manuscriptbeoordeling</option>
</select>
Is there a way to do this?
]]> I’m really hoping that someone can help me out here, I’m trying to give the admin the ability to choose a page for a button to link to. I’ve created the select using
wp_dropdown_pages($args)
and am creating the arguments via
$args = array(
'echo' => 1,
'selected' => $the_link,
'name' => 'theme_option[the_link]');
and have attempted to save the value generated
$input['the_link'] = (int) $input['the_link'];
… but so far no luck. The selected option just resets once the form has been sent, and it doesn’t look like the value is getting saved at all. Does anyone have any advice?
I’m creating a responsive theme. All seems to be going fine until I got to replacing the Navigation bar menu at full screen with dropdown menu at 500px or below. I got the dropdownmenu quite alright, but the options are not coming up as links. I used the wp_dropdown_pages() template tag to generate the dropdown; however, the select options are not coming up as links. I’ve check all the parameters of wp_dropdown_pages() on the codec but non seems to give the option I need. I’ll appreciate any help or direction on this.
Thank you.
]]>