我试图将滑块自定义帖子类型集成到WordPress中,但我似乎无法设置该自定义帖子类型的顺序(orderby:ID,order:ASC)。
我添加了supports => array(\'title\',\'page-attributes\'),
但当我更改幻灯片的顺序属性时,它不会更改其顺序(无论是在后端还是前端)。
这就是功能。php(它也会出现以下错误:Notice: Undefined index: post_type in .../functions.php on line 105
)
function set_custom_post_types_admin_order($wp_query) {
$post_type = $wp_query->query[\'post_type\']; // line 105
if ( $post_type == \'bxslider\') {
$wp_query->set(\'orderby\', \'ID\');
$wp_query->set(\'order\', \'ASC\');
}
}
add_filter(\'pre_get_posts\', \'set_custom_post_types_admin_order\');
这是bxslider。php
<?php
// Create Slider
function hostify_bxslider_template() {
// Query Arguments
$args = array(
\'post_type\' => \'bxslider\',
\'orderby\' => \'ID\',
\'order\' => \'ASC\',
\'posts_per_page\' => -1
);
// The Query
$the_query = new WP_Query( $args );
// Check if the Query returns any posts
if ( $the_query->have_posts() ) {
// Start the Slider ?>
<div id="slider">
<?php
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div>
<div class="slide">
<?php // Check if there\'s a BxSlider h2 given and if so post it
if ( get_post_meta( get_the_id(), \'bxslide_metabox_h2\', true) != \'\' ) { ?>
<h2><?php echo get_post_meta( get_the_id(), \'bxslide_metabox_h2\', true); ?></h2>
<?php } ?>
<?php // Check if there\'s a BxSlider h1 given and if so post it
if ( get_post_meta( get_the_id(), \'bxslide_metabox_h1\', true) != \'\' ) { ?>
<h1><?php echo get_post_meta( get_the_id(), \'bxslide_metabox_h1\', true); ?></h1>
<?php } ?>
<?php // Check if there\'s a BxSlider paragraph given and if so post it
if ( get_post_meta( get_the_id(), \'bxslide_metabox_text\', true) != \'\' ) { ?>
<p><?php echo get_post_meta( get_the_id(), \'bxslide_metabox_text\', true); ?></p>
<?php }
// Check if there\'s a BxSlider button link or button name given and if so post it
if ( get_post_meta( get_the_id(), \'bxslide_metabox_link\', true) != \'\' || get_post_meta( get_the_id(), \'bxslide_metabox_name\', true) != \'\' ) { ?>
<a href="<?php echo esc_url( get_post_meta( get_the_id(), \'bxslide_metabox_link\', true) ); ?>" class="button2"><?php echo get_post_meta( get_the_id(), \'bxslide_metabox_name\', true); ?></a>
<?php } ?>
<div class="clear"></div><br />
</div>
</div>
<?php endwhile; } ?>
</div>
<?php
// Reset Post Data
wp_reset_postdata();
}
?>
另外,滑块工作得很好,我只是不能改变幻灯片的顺序。