I'm confused how to properly tackle this and the amount of information on the subject isn't very direct. I am trying to develop a custom slider for my homepage and needed to create a custom taxonomy 'slider' to tag which posts could be included in the slideshow.
Here's the code I used:
add_action( 'init', 'create_slider_taxonomies', 0 );
function create_slider_taxonomies() {
$labels = array(
'name' => _x( 'Sliders', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Slider', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search Sliders', 'textdomain' ),
'all_items' => __( 'All Sliders', 'textdomain' ),
'parent_item' => __( 'Parent Slider', 'textdomain' ),
'parent_item_colon' => __( 'Parent Slider:', 'textdomain' ),
'edit_item' => __( 'Edit Slider', 'textdomain' ),
'update_item' => __( 'Update Slider', 'textdomain' ),
'add_new_item' => __( 'Add New Slider', 'textdomain' ),
'new_item_name' => __( 'New Slider Name', 'textdomain' ),
'menu_name' => __( 'Slider', 'textdomain' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'slider' ),
'show_in_rest' => true, // need to show this in order for option to display under the 'Document' panel in a post
);
register_taxonomy( 'slider', array( 'post', 'slider' ), $args );
}
And it showed up in the post just fine:
Now, I'm unsure how to query a list of the posts so that I can assemble the content onto a page.
I thought that I could do some variation of my $wp_query that I use for the archive page, but that didn't seem to work:
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query();
$wp_query->query(array(
'posts_per_page' => -1,
'taxonomy' => slider,
'field' => slug,
'terms' => homepage
));
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
Maybe this isn't the best way to do this. But I don't want to rely on yet another third party plugin especially when the majority of slider plugins don't feature content the way that I want them to.
Any suggestions will be appreciated. Thank you!