Hello Raidje
Generally, it’s required the woocommerce installed for your site to order any posts.
Instead of posts, you can manage it by the WooCommerce products to order anything.
Thanks.
Thread Starter
raidje
(@raidje)
thank you but it’s not a solution for me. i don’t sale anything and i don’t want to use woocommerce just for this.
Does the last name exist on its own in any post (or order) data, such as post meta or custom fields (or related data such as a registered user)? Extracting the last name out of a title for the purpose of ordering posts gets a bit involved. Ordering by a post meta field involves a relatively simple change to the posts query. Extracting last name out of a title involves development a custom ordering algorithm. Not as complicated as it may sound, but more involved none the less.
Such an algorithm is also much less efficient in delivering ordered results. If a lot of posts are involved, it might be worth creating a custom field for the purpose if one does not already exist. A one time script could do so for existing posts. Some custom code would be needed to do so for new posts. Likely beyond reach for non-developer DIY, but IMO would be the optimal solution if you have some spare funds for hiring some professional help.
For the record, soliciting paid help in these forums is not allowed. I’m only pointing out that it’s an option available to you through other channels. Things would be much easier to sort by first name, actually sort by entire post title. Same first names would then be sorted secondarily by last.
Thread Starter
raidje
(@raidje)
bcworkz, thank you for your reply.
so you suggest i could use the custom field to register the last name. This tag could be unique in fact.
so with that how to re-order posts from a specific category by the custom field ?
Ordering by a custom field value still requires some custom coding. But the basic code is relatively simple, developer-type skills not required. The complication is in having the code only order the query you want so ordered and not everything else. Here’s an example that orders only back end queries for post type “order” by a field keyed as “lastname”:
add_action('pre_get_posts', 'rdj_order_orders', 999 );
function rdj_order_orders( $query ) {
if ( is_admin() && $query->is_main_query() && 'order' == $query->get('post_type')) {
$query->set('meta_key', 'lastname');
$query->set('orderby', 'meta_value');
}
}
This can go in functions.php of your theme (preferably that of a child theme). Alter as needed to suit your specific need.
Thread Starter
raidje
(@raidje)
thank you for your help bcworkz
it works, great support from you !!
have a nice day