Created
December 7, 2010 23:25
-
-
Save iammerrick/732629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Post Page Binder | |
Plugin URI: http://risermedia.com | |
Description: A way to bind posts and pages using custom meta data. | |
Version: 1 | |
Author: Merrick Christensen | |
Author URI: http://risermedia.com | |
*/ | |
defined('ABSPATH') or die('No direct script access.'); | |
class Post_Page_Binder | |
{ | |
public function __construct() | |
{ | |
add_action('admin_menu', array($this, 'action_add_pages_box')); | |
add_action('save_post', array($this, 'action_save_post')); | |
} | |
public function action_add_pages_box() | |
{ | |
add_meta_box('Did You Know?', __( 'Did You Know?', 'did you know?' ), array($this, 'pages_box'), 'page', 'side', 'low'); | |
} | |
public function pages_box() | |
{ | |
global $post; | |
global $wpdb; | |
$page_ids = $wpdb->get_results('SELECT ID FROM wp_posts WHERE post_type = "did_you_know" AND post_status = "publish" GROUP BY ID'); | |
$html = NULL; | |
$html .= '<p><strong>Did You Know?</strong></p>'; | |
$html .= '<select name="did_you_know_id">'; | |
$html .= '<option value="NULL">Select One</option>'; | |
foreach($page_ids as $page_id) | |
{ | |
$html .= '<option value="'.$page_id->ID.'">'.get_the_title($page_id->ID).'</option>'; | |
} | |
$html .= '</select>'; | |
$html .= '<p>If this uses a "Custom Product" category page template, what "Did You Know?" content would you like featured?</p>'; | |
echo $html; | |
} | |
public function action_save_post($post_id) | |
{ | |
print_r($_POST); // works and contains did_you_know_id key | |
echo('>>>>>'.$_POST['did_you_know_id']); // Fails... what!? | |
if( ! empty($_POST['did_you_know_id'])) | |
{ | |
echo $_POST['did_you_know_id']; | |
/*if( ! update_post_meta($post_id, 'did_you_know_id', $_POST['page'])) | |
{ | |
add_post_meta($post_id, 'did_you_know_id', $_POST['page'], true); | |
}*/ | |
} | |
} | |
} | |
new Post_Page_Binder(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment