Created
July 14, 2016 14:18
-
-
Save enlacee/259e832b086b75c8217558a8ec6a89a5 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 | |
// create two taxonomies, genres and writers for the post type "book" | |
function create_book_taxonomies() { | |
// Add new taxonomy, make it hierarchical (like categories) | |
$labels = array( | |
'name' => _x( 'Genres', 'taxonomy general name' ), | |
'singular_name' => _x( 'Genre', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Genres' ), | |
'all_items' => __( 'All Genres' ), | |
'parent_item' => __( 'Parent Genre' ), | |
'parent_item_colon' => __( 'Parent Genre:' ), | |
'edit_item' => __( 'Edit Genre' ), | |
'update_item' => __( 'Update Genre' ), | |
'add_new_item' => __( 'Add New Genre' ), | |
'new_item_name' => __( 'New Genre Name' ), | |
'menu_name' => __( 'Genre' ), | |
); | |
$args = array( | |
'hierarchical' => true, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'genre' ), | |
); | |
register_taxonomy( 'genre', array( 'book' ), $args ); | |
// Add new taxonomy, NOT hierarchical (like tags) | |
$labels = array( | |
'name' => _x( 'Writers', 'taxonomy general name' ), | |
'singular_name' => _x( 'Writer', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Writers' ), | |
'popular_items' => __( 'Popular Writers' ), | |
'all_items' => __( 'All Writers' ), | |
'parent_item' => null, | |
'parent_item_colon' => null, | |
'edit_item' => __( 'Edit Writer' ), | |
'update_item' => __( 'Update Writer' ), | |
'add_new_item' => __( 'Add New Writer' ), | |
'new_item_name' => __( 'New Writer Name' ), | |
'separate_items_with_commas' => __( 'Separate writers with commas' ), | |
'add_or_remove_items' => __( 'Add or remove writers' ), | |
'choose_from_most_used' => __( 'Choose from the most used writers' ), | |
'not_found' => __( 'No writers found.' ), | |
'menu_name' => __( 'Writers' ), | |
); | |
$args = array( | |
'hierarchical' => false, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'update_count_callback' => '_update_post_term_count', | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'writer' ), | |
); | |
register_taxonomy( 'writer', 'book', $args ); | |
} | |
function codex_custom_init() { | |
$args = array( | |
'public' => true, | |
'label' => 'Books', | |
); | |
register_post_type( 'book', $args ); | |
} | |
add_action( 'init', 'codex_custom_init' ); | |
function add_taxonomies_to_pages() { | |
register_taxonomy_for_object_type( 'writer', 'book' ); | |
//register_taxonomy_for_object_type( 'category', 'book' ); | |
} | |
add_action( 'init', 'add_taxonomies_to_pages' ); | |
add_action('init', 'movie_register'); | |
function movie_register() { | |
$labels = array( | |
'name' => _x('Movies', 'movie type general name'), | |
'singular_name' => _x('Movie', 'deail type singular name'), | |
'add_new' => _x('Add New', 'movie item'), | |
'add_new_item' => __('Add New Movie Item'), | |
'edit_item' => __('Edit Movie Item'), | |
'new_item' => __('New Movie Item'), | |
'view_item' => __('View Portfolio Item'), | |
'search_items' => __('Search Movie'), | |
'not_found' => __('Nothing found'), | |
'not_found_in_trash' => __('Nothing found in Trash'), | |
'parent_item_colon' => '' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'query_var' => true, | |
'rewrite' => true, | |
'capability_type' => 'post', | |
'hierarchical' => false, | |
'menu_position' => null, | |
'taxonomies' => array('post_tag') | |
); | |
//register what we just set up above | |
register_post_type('movie', $args); | |
} | |
/* | |
$myargs = array( | |
'posts_per_page' => 5, | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
'tag' => 'dia' | |
// 'tag_slug__and' => array('dia'), | |
// 'caller_get_posts'=>1 | |
); | |
$query = new WP_Query($myargs); | |
*/ | |
$args = array( | |
//'numberposts' => 5, | |
'post_type' => 'book', | |
'tag__in' => array(2) | |
); | |
$myposts = get_posts($args); | |
// 02 | |
/*$posts_array = get_posts( | |
array( | |
'posts_per_page' => -1, | |
'post_type' => 'book', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'writer', | |
'field' => 'term_id', | |
'terms' => 2, | |
) | |
) | |
) | |
);*/ | |
/* | |
echo "<pre>"; | |
print_r($myposts); | |
echo "</pre>"; | |
exit; | |
*/ | |
$args=array( | |
'post_type' => 'movie', | |
'tag' => 'tagmovie1', | |
'showposts'=>5, | |
//'caller_get_posts'=>1 | |
); | |
$my_query = new WP_Query($args); | |
if( $my_query->have_posts() ) { | |
echo '5 recent Posts with tag1'; | |
while ($my_query->have_posts()) : $my_query->the_post(); ?> | |
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> | |
<?php | |
endwhile; | |
} //if ($my_query) | |
wp_reset_query(); // Restore global post data stomped by the_post(). | |
exit; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment