[Plugin: FlexSlider] Custom Post Type Ordering Slides
-
Hi,
I am trying to implement the flexslider, so that i can set the page attribute and order it using the ‘order’ (menu_order).
I have created a custom post type in my functions.php
function custom_post_image_silder() { $labels = array( 'name' => _x( 'Image-Slider', 'post type general name' ), 'singular_name' => _x( 'Image-Sliders', 'post type singular name' ), 'add_new' => _x( 'Add New', 'Image' ), 'add_new_item' => __( 'Add New Image' ), 'edit_item' => __( 'Edit Image' ), 'new_item' => __( 'New Image' ), 'all_items' => __( 'All Image' ), 'view_item' => __( 'View Image' ), 'search_items' => __( 'Search Image' ), 'not_found' => __( 'No images found' ), 'not_found_in_trash' => __( 'No products found in the Trash' ), 'parent_item_colon' => '', 'menu_name' => 'Image-Slider' ); $supports = array( 'title', 'editor', 'author', 'custom-fields', 'revisions', 'thumbnail', 'page-attributes' ); $details = array( 'labels' => $labels, 'description' => 'Images For Image Slider', 'public' => true, 'menu_position' => 5, 'supports' => $supports, 'has_archive' => true, ); register_post_type( 'image-slider', $details ); } add_action( 'init', 'custom_post_image_silder' );
Then when i create a new image i set the page attribute order such as Image 1 Order 1, Image 2 order 2, Image 3 order 3.
In my front-page.php i set the flexlider arguments.
<section id="content-slider"> <div id="content-slider-main"> <?php $args = array( 'post_type' => 'image-slider', 'orderby' => 'menu_order', 'order' => 'ASC' ); $slides = new WP_Query($args); print_r($slides); ?> <?php if ($slides->have_posts()) : ?> <div class="flexslider"> <ul class="slides"> <?php while ($slides->have_posts()) : $slides->the_post(); ?> <li> <a target="_blank" href="<?php echo get_post_meta($post->ID, 'image_link', true); ?>"> <?php the_post_thumbnail('image-slider'); ?> <?php $image_caption = get_post_meta($post->ID, 'image_caption', true); if (!empty($image_caption)) { ?> <p class="flex-caption"><?php echo $image_caption; ?></p> <?php } ?> </a> </li> <?php endwhile ?> </ul> </div> <?php endif; ?> </div> </section>
However, it is not ordering the posts correctly, it goes 3, 1 2.
Here is the SQL it generates when i print_r($slides)
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'image-slider' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.menu_order ASC LIMIT 0, 10
I then run this in phpmyadmin and it shows correctly the 3 posts/images, post id of 32/35/37 in that order, and it is the exact order i did using the order attribute 1/2/3. So i am confused why when it shows in the slider the ordering is 3(37)/1(32)/2(35)
- The topic ‘[Plugin: FlexSlider] Custom Post Type Ordering Slides’ is closed to new replies.