請問如何根據ACF中的字段(參見圖片)對我的產品(這是我的自定義帖子類型)進行排序?排序我的自定義文章中的產品中的ACF字段在Wordpress中
這裏是我的自定義字段代碼:
/******* *******/
/* CUSTOM POST TYPE */
/******* *******/
// Custom Post Type - product
function register_post_product() {
$labels = array(
'name' => __('Products', '_tk'),
'singular_name' => __('Product', '_tk'),
'add_new' => __('Add product', '_tk'),
'add_new_item' => __('Add New product', '_tk'),
'edit_item' => __('Edit product', '_tk'),
'new_item' => __('New product', '_tk'),
'all_items' => __('All products', '_tk'),
'view_item' => __('View product', '_tk'),
'search_items' => __('Search product', '_tk'),
'not_found' => __('No product found', '_tk'),
'not_found_in_trash' => __('No product found in the Trash', '_tk'),
'parent_item_colon' => '',
'menu_name' => __('Products', '_tk'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'supports' => array('title', 'editor', 'page-attributes', 'thumbnail'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'rewrite' => array('slug' => 'produkty','with_front' => false),
'menu_position' => 6,
'menu_icon' => 'dashicons-hammer'
);
register_post_type('product', $args);
}
add_action('init', 'register_post_product');
我做在谷歌一些搜索,我想這樣的排序是:
add_filter('pre_get_posts', 'my_get_posts');
function my_get_posts($query) {
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
$query->set('meta_query','capacity');
return $query;
}
,但沒有結果。
不幸的是我重新擁有空白包sult –