Sorting Woocommerce Attributes alphabetical in Admin - wordpress

When there are a lot of variations and you want to edit your stock per variation, the list of variants is not logical (in the admin). When you want to edit 1 variation you have to search the whole list (250+) to find it.
I found a solution here;
Change alphabetical sorting of attributes / variations on product page in Woocommerce shop
But when I edit a bulk edit a price and save the product, only the first 41 are updated. It is because of this line;
'orderby' => 'menu_order',
This is my code;
$args = array(
'post_type'=>'product_variation',
'post_status' => array( 'private', 'publish' ),
'posts_per_page' => -1,
'meta_key' => 'attribute_pa_kleur', //rename with your attributes
'post_parent' => $post->ID,
'meta_query' => array(
array(
'key' => 'attribute_pa_kleur' //rename with your attributes
),
)
);
How can I fix this?

Related

Wordpress get posts[relationship] from users

I have a case in which I have 2 custom post types, let's say they are projects and teams. Using Advanced custom fields, I have a relationship field while creating a project and I'm assigning which teams are working on it. (Important: there is no custom field in the teams post type). Later on, I want on single-team, to list all the projects that this team was working on.
The example that Advanced custom fields has is where you have a custom field in the team, not in the project, and I need to do the opposite. (Here is how acf documentation is https://www.advancedcustomfields.com/resources/querying-relationship-fields/).
I tried doing this, but it doesn't work, it says that I don't post a correct data.
$team_id = get_the_ID();
$posts = get_posts(array(
'post_type' => 'projects',
'orderby' => 'teams',
'post__in' => $team_id,
));
Since the ACF relationship field is located in your Project custom post type in your single-team.php file where you want to list of the projects on which the team member worked on you can do the following:
$args = array(
'post_type' => 'PROJECTS CPT NAME HERE',
'post_status' => 'publish',
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'ACF RELATIONSHIP FIELD NAME HERE',
'value' => get_the_ID(), // the ID of the member
'compare' => 'LIKE',
)
)
);

Woocommerce product filter meta key

I have built a search a form at custom page in wordpress and want to filter product on shop page using meta keys that are already exists into posts table.
Initially I have tried to filter categories at form page like this but it doesn't work.
$meta_query = array(
'key' => '_years',
'value' => '2009'
);
$args=array(
'meta_query' => $meta_query,
'posts_per_page' => 10,
'post_type' => 'product',
'orderby' => $orderby,
'order' => $order,
'paged' => $paged
);
wc_product_dropdown_categories($args);
The meta_query parameter must be change in an array of array for a single custom field handling:
$meta_query = array(
array(
'key' => '_year',
'value' => '2009',
'compare' => '>',
)
);
Some details from WP_Query page in the Single Custom field handling part
Hope it will work with this.

WooCommerce shop page display products above $50

I have coded up a woocommerce theme and the website has a shop page. You can find out the shop page http://bit.ly/1TSMKrV
Now, I need few things to happen on this page
The products which are priced more than $50 should only display
The products must be sorted by popularity
The filters on the left side must function properly
I have tried to place the following code above the while loop
$args = array(
'post_type' => 'product',
'paged' => $page,
'posts_per_page' => 15,
'meta_key'=>'_sale_price',
'meta_query' => array(
array(
'key' => '_sale_price',
'value' => '50',
'compare' => '>',
'type' => 'NUMERIC'
)
)
);
But this code just fulfils the first condition and not the other. For time being, I have removed the code and just used the default while loop that Woo Commerce provides.
Let me know where I am going wrong.
Thanks in advance!

Wordpress sort by meta_value not working with meta_query

I have a template that pulls a custom post type for properties and sorts them by state. The script works properly until you add in a meta_query for the agent. It pulls the correct properties, but it doesn't sort them by state with the meta_query present. Here's the query:
$qry = array(
'post_type' => array( 'practices-tpsg' ),
'meta_key' => 'wpcf-practice-state',
'orderby' => 'meta_value',
'order' => 'asc',
'showposts' => 18,
'paged' =>$paged
);
if($_GET['agent'])
{
$qry['meta_query'] = array(
'relation' => 'OR',
array(
'key' => 'wpcf-agent',
'value' => $_GET['agent']
),
array(
'key' => 'wpcf-agent2',
'value' => $_GET['agent']
),
);
}
Does anyone know why it would stop sorting properly after the meta_query is added to the query?
Here's a link to the page: http://www.totalpracticesolutionsgroup.com/practices-for-sale/ The sort order works properly in the default view, which allows the state name headers above the listings. If you select an agent from the drop down in the top right, the correct properties are pulled, but they are no longer sorted by state. You can also see the output of the query by adding &debug=1 to the end of the url.
replace 'orderby' => 'meta_value' with 'orderby' => 'meta_value_num

Wordpress sort posts by multiple meta values

i would like to sort my posts first by "time" meta value and secondly by "clicks" meta value.So if 2 posts have the same "time" the one with less clicks will go first.
$args=array(
'post_type' => 'post',
'category_name' => 'players',
'order' => 'ASC',
'meta_key' => 'times',
'posts_per_page'=> '15',
'orderby' => 'meta_value_num',
'offset' => $offsetnumber
);
You can hook into the posts_orderby filter to customize the sql query to sort by multiple fields.
Some details here:
http://jeffgran.com/262/blog/wordpress-sort-posts-by-multiple-fields-part-ii

Resources