Pourriez-vous s'il vous plaît me dire comment trier mes produits (c'est mon type de poste personnalisé) par le champ (voir photo) dans ACF?Trier par champ ACF dans les produits dans mon Custom Post Type dans Wordpress
Voici mon code de champ personnalisé:
/******* *******/
/* 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');
je fait une recherche dans google et j'ai essayé de trier comme ça:
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;
}
Mais sans résultats.
Malheureusement, je avoir le bage blanc en re sult –