如何通过动态WORDPRESS设置后序



图像1

大家好

我已经创建了一个自定义的帖子类型和各种自定义字段。我想控制每个帖子的顺序,所以我创建了一个名为";订单";。目前,我只是在这个字段中手动输入一个数字,作为我希望该职位在列表中的位置。这样做的问题是,如果我说想把8号职位调到3号职位,我需要进入每个职位,并相应地改变顺序。

这里的示例:https://prnt.sc/vua6dm

我需要单独更改帖子的顺序,这也会更改前端

首先需要创建一个名为order的元盒,然后创建以下代码:

<?php
$price_query_args = array(
'meta_key' => 'order',
'meta_value' => "",
'meta_compare' => '!=',
'post_type' => array('post'),
);
<?php if (have_posts()):?>
<ul style="display:flex;">
<?php  while (have_posts()):the_post();?>
<li style="order:<?php echo get_post_meta(get_the_ID(), 'order', true); ?>;" >
<img src="<?php $image=wp_get_attachment_image_src(get_post_thumbnail_id( $post -> ID ),'single-post-thumbnail' ); echo $image[0]; ?>" style="width:100%">
<label class="order"><?php echo get_the_title(); ?></label>
<div class="btn-pro" >
<a href="<?php the_permalink(); ?>/#tab1">bulk</a>
<a href="<?php the_permalink(); ?>/#tab2">pack</a>
</div>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>

最新更新