Created
December 9, 2016 03:37
-
-
Save anonymous/f7f558a0cb2221d494509545ce2ebd8f to your computer and use it in GitHub Desktop.
Query Taxonomy and Show terms into post and pages Plugin (Add this inside another folder)
This file contains hidden or 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: Tax Query | |
Plugin URI: | |
Description: Prints Taxonomies into post or pages | |
Version: 1.0 | |
Author: Juan Pablo De la torre | |
Author URI: | |
License: GPL2 | |
licence URI: https://www.gnu.org/licenses/gpl2-.0.html | |
*/ | |
function show_taxonomies(){ | |
add_meta_box('ga-metaboxes', 'Show Taxonomies', 'taxonomies_container', array('post', 'page'), 'normal', 'high', null); | |
} | |
add_action('add_meta_boxes', 'show_taxonomies'); | |
function taxonomies_container($post) { | |
wp_nonce_field(basename(__FILE__), "meta-box-nonce" ); | |
?> | |
Mood: | |
<?php | |
$terms = get_terms( 'mood', array( | |
'hide_empty' => false, | |
) ); | |
?> | |
<select name="mood"> | |
<?php foreach($terms as $key => $term): | |
if($term->term_taxonomy_id == get_post_meta($post->ID, "mood", true )) { | |
echo '<option selected>' . $term->name . '</option>'; | |
} else { | |
echo '<option value="' . $term->term_taxonomy_id . '">' . $term->name . '</option>'; | |
} | |
endforeach; ?> | |
</select> | |
<?php | |
} | |
add_action('save_post', 'tax_save_post'); | |
function tax_save_post($post_id, $post, $update){ | |
if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__))) | |
return $post_id; | |
if(!current_user_can("edit_post", $post_id)) | |
return $post_id; | |
if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE) | |
return $post_id; | |
$input_metabox =''; | |
$textarea_metabox =''; | |
$dropdown_metabox = ''; | |
$mood = ''; | |
if(isset($_POST["mood"])) { | |
$mood = $_POST["mood"]; | |
} | |
update_post_meta($post_id, "mood", $mood ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment