Trying to sort and display categories(not posts) by custom field: 'order'

I'm a WordPress rookie. I've added a custom field to my "Category" taxonomy. The custom field is "custom_order" and its purpose is to hold a number so that my categories can be sorted and displayed in the order I choose. My problem is that I can't get them to sort; I can display the categories, and 'echo' each category's "custom_order" number, but I must be missing something when it comes to accessing and sorting the meta_value. Not sure if I'm …
Category: Web

Next/Previous Product with custom order by price & products inside the product category

How to create next/prev buttons that are price sorted and give results inside the product category you are in? This question has been asked multiple times and despite the multiple threads there wasn't an exact answer. Only relatively close ones that didn't do all of the above. Below you will find my answer which works in my tests so far.
Category: Web

Compare ACF date field (if exists) and post date and order DESC

I have an ACF date field (same format as post date) and in my Query I want it to be compared to the publish date of the post: If erstelldatum is not empty use erstelldatum for order If erstelldatum is empty use publish date for order instead Order descending My code is working so far but the order isn`t right. It lists all posts with erstelldatum first followed by those without. I want them to be ordered descending by the …
Category: Web

Make custom post type column sortable

My site has two custom types: Auction and Lot. Lots are connected to an Auction via the post_parent field. I added an Auction column to the Lots list in the admin area. function theme_lot_custom_columns($columns){ $new = array(); foreach($columns as $key => $value) { if ($key=='date') { // Put the Auction column before the Date column $new['auction'] = __('Auction'); } $new[$key] = $value; } return $new; } add_filter('manage_lot_posts_columns', 'theme_lot_custom_columns'); function theme_lot_custom_column($column, $post_id) { if ($column === 'auction'){ $post = get_post($post_id); if …
Category: Web

Sort categories by meta value

How can I make a list of categories with 4 last posts in each where every category is sorted by meta_value. For example, template without sorting by meta_value is http://pastebin.com/AeH6vx9b It displays parent categories only. Few days I am searching something related to categories extra fields but can't find something workable. This is my best search result. What I have to do with this? I don't understand it. Is it possible to do what I want?
Category: Web

Can the Next/Prev Post links be ordered by menu order or by a meta key?

I have a series of posts that are ordered by a meta_key value. They could also be arranged by menu order, if necessary. The next/prev post links (generated by next_post_link, previous_post_link, or posts_nav_link all navigate by chronology. While I understand this default behaviour, I don't understand how to change it. I found that it maps through to adjacent_post_link in link-template.php, but then it starts to seem fairly hard-coded. Is it recommended to re-write this from scratch to replace it, or …
Category: Web

Meta query with order by another custom field

Edit: I will try to explain in detail my problem. I am working on a portfolio site. There are a few custom post types: Projects, Publications, Exhibitions, Lectures and Slides. Home page consists of following sections: slider with Slides portfolio consisting of: selected (marked by Client) Projects, Publications, Exhibitions and Lectures and remaining Projects, Publications, Exhibitions and Lectures awards section Now, I have problem with the portfolio section. It is to be paged in order to use Infinite Scroll by …
Category: Web

Sort users by meta key value even if meta key not present for all users

Only some users have a specifice meta_key some_metakey associated with their ID. The following args successfully orders users with a specified role by some_metakey but only those with that meta_key. Can anyone point the direction to change the args to include ALL users with a specified role even if they do not have the some_metakey meta_key? $args = array( 'role__in' => [ 'role1', 'role2', 'role3', 'role4' ], 'order' => 'DEC', 'meta_key' => 'some_metakey', 'orderby' => 'meta_value' ); $users = get_users( …
Category: Web

Sorting Custom Posts on Archive page with pagination

I've got custom taxonomy archive pages with a drop down list that allows users to re-order/sort the posts. It basically waits for the user to select from the drop down then uses array_merge( $wp_query->query..... to create a new query and re-sort the posts. This works fine. I also use wp-pagination to display numbered pagination. This also works fine. The problem is, when a user re-sorts the list, and then clicks on the pagination to go to page 2 the new …
Category: Web

manage_edit-{post_type}_sortable_columns sorts, but wrong!

Good afternoon! This is an issue regarding the Wordpress backend and custom post types. I have spent all Friday searching and trying possible solutions and, while they helped others, in my case they're not doing what I need. Status quo I have a custom post type called "anco_project" it uses very few WP given data-fields but more custom ones from the ACF addon including a field called "anco_project_year_from" and one called "anco_project_year_to", both set up as a 'true number' format. …
Category: Web

How to sort custom post's category by id from the theme's function.php?

I'm wondering how to sort a custom post's categories in the selection field which I've circled in the screenshot? And I have the following code which generates category listing $args=array( 'class' => 'select-submit2', 'hide_empty' => false, 'selected' => $prop_category_selected, 'name' => 'prop_category', 'id' => 'prop_category_submit', 'orderby' => 'NAME', 'order' => 'ASC', 'show_option_none' => __('None','wpestate'), 'taxonomy' => 'property_category', 'hierarchical'=> true ); wp_dropdown_categories( $args ); ?>
Category: Web

How to change custom post order ASC/DESC menu_order wise dynamically?

I have created custom post type in back end with sort menu_order post as you can see in the screenshot. http://prntscr.com/gacw95 In back end sorting ASCENDING/DESCENDING working fine. But I need to Sort ASC/DESC on the front side also. When I click on order tab in back end It will be sorting the post in back end but not in front end. How can I sort the custom post in front side when change in the back end? Backend code …
Category: Web

WP_Query, Taxonomy, list of attached items to a Term, sorted

I have a Taxonomy, “Genre”. “Genre” has a Term, “advert”. I want my taxomomy template to grab all Custom Posts attached to that term, sort them by my last_name, first_name, short_title Custom Fields, and output. But my custom query is returning 0 posts! I would love to get another set of eyes on this. I’m missing something! <?php $args = array( 'tax_query' => array( array( 'taxonomy' => 'genre', 'terms' => array( 'advert' ) ) ), 'meta_query' => array( 'relation' => …
Category: Web

How to order query results based on if a custom field has been populated, then the order by the date of the post?

I am trying to custom sort a query for product posts (custom content type) based on if a specific ACF custom field for a product ID number has been populated. My client wants to feature products with this first as it adds extra details for inventory. My current script works to a degree, but doesn't seem to factor date into the order/sort so I am assuming it is sorting based on the actual product ID number, versus if it just …
Category: Web

Sort query_terms_list for post_tags alphabetically

I have the following array that currently sorts tags by tag count and returns the tags with the individual tag count. I would like to keep the individual tag count but sort the tags alphabetically instead. I tried to change arsort( $list ) to sort ( $terms->name ) but I think my logic here is completely off. Any assistance is much appreciated :) Example: change from: oranges(20 )apples(12) bananas(10) to: apples(12) bananas(10) oranges(20) function get_query_terms_list( $taxonomy = 'post_tag', $sep = …
Category: Web

ORDER BY custom field value out of where clause

Based on example here https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/ I'd like to modify the query $q = new WP_Query( array( 'meta_query' => array( 'relation' => 'AND', 'state_clause' => array( 'key' => 'state', 'value' => 'Wisconsin', ), 'city_clause' => array( 'key' => 'city', 'compare' => 'EXISTS', ), ), 'orderby' => 'city_clause') ); to be able to get all posts where state is 'Wisconsin' OR state is 'California' and ORDER BY population DESC. I'm failing in writing such query in WP. Any tips would be much …
Category: Web

How to Arrange Posts by Size in the WordPress Dashboard?

This may be a lame question, but I can't find an answer to this. Let's say you have a ton of empty posts that you want to delete. Obviously those who have some content will have more size. Is there any option to sort posts by size in WordPress dashboard? Even better, is there any option to automatically prevent posts from beeing published without any content? Through fuctions.php maybe? Would appreciate your help!
Category: Web

Wp Query sort order from custom MetaBox

I am trying to sort a list of post based of the meta_key deal amount, which would be to display the highest deal first and work its way down to smaller deal amounts. The deal amount would be anywhere from 1,000 to 9,000,000. Currently the below code is sorting the deal amounts based on the first number. So if I have a transaction that is 6,000 and 6,000,000 they put them side by side instead of displaying the 6,000,000 first. …
Category: Web

How to sort by meta value num, but ignore zero value?

I have custom-post-type company and taxonomy services for this CPT. I have created meta-field service_[id]_price for companies and fill this field with a number. If this company has not price for this service, I fill 0 in this field. On the services page, I need a list of companies sorted by current service price ASC. In this case, I first get all companies with "0" value in this field. But I need to get all companies where this field has …
Category: Web

Custom post type taxonomy not sorting correctly

i created a custom post type and also some taxonomy to be able to perform sorting on the display list. It is all working well on my local testing installation but as soon as i put on the production website (where there is some other plugins etc installed compared to my local), then the sorting is not working anymore, any idea ? Here some part of the plugin code related to my taxonomy and custom post type : add_action('init', 'students_init'); …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.