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

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

How do I order pages and categories by ID or name in the same query?

I would like to query most of my pages and categories on the homepage. So far I am able to get the pages and category (posts), but I cannot order the list the way I want to. I want to be able to get a custom order like page, posts from a category, another page, and posts from another category. I am using the following: <?php $args = array( 'cat' => $current, 'post_type' => array( 'page', 'post'), 'orderby' => 'ID' …
Category: Web

Show first posts with custom field not empty and order all by title

I have a custom post type called "products". My goal is to make my custom query that I have on homepage and also the search query show first the posts that have a custom field called "id_number" not empty and then the other posts that have the "id_number" empty. All should be ordered by title. This is my code so far only for my custom query. I also need it for search page query but I didn't get that far. …
Category: Web

User list order by user meta

i have created user vote that can vote users or author of posts. so for example have 4 users which looks: user --- ID=1 --- META KEY='_thumbs_rating_up' --- META VALUE='13' user --- ID=2 --- META KEY='_thumbs_rating_up' --- META VALUE='17' user --- ID=3 --- META KEY='_thumbs_rating_up' --- META VALUE='8' user --- ID=4 --- META KEY='_thumbs_rating_up' --- META VALUE='241' So i must order these users by user meta key and meta value from heighest to lowwer. So i have these code now …
Category: Web

Order WP_Query by The Order of an Array in Tax_Query

I have a wp_query that uses tax_query to which I pass an array of taxonomy term IDs. I'd like to order my results based on the order of that array but can't get it to work and searching has got me nowhere. Example code below for reference. So this code actually orders the results by tax terms (dumb luck?) but the tax terms aren't in the same order as $term_array. I've tried all the logical options for the 'orderby' parameter …
Category: Web

Sort on meta value but include posts that don't have one

I've been modifying the built in WP search using the pre_get_posts filter, allowing the user to sort the posts (including a bunch of custom post types) by different fields. The problem I'm having though is that when I tell WP to sort by a meta value it will exclude all posts that don't have that meta value set. This causes the number of results to change if you change sorting from say "Price" to "Date" because "Posts" don't have "Price" …
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

Sort by an ACF field in a tax_query

I do not find the solution which must surely be surely simple. (I'm new to WP) I have an ACF field named "partners_order". I would like to sort it in ascending order (ASC) here's what i tried <?php $terms = get_terms('type_partenaires'); usort($terms, function($a, $b) { return get_field('ordre_affichage', $a) - get_field('ordre_affichage', $b); }); foreach ( $terms as $term ): ?> <?php echo $term->name; ?> <?php $loop = new WP_Query( array( 'post_type' => 'partenaires', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => …
Category: Web

Order post by year DESC and month ASC

I have a worpresss 4.0.12 website; i created a custom template category-$id.php in which I have to show post ordering them by Year DESC and by month ASC (or a custom field ASC), the result should be something like this: 2017 Post 10-01-2017 Post 25-01-2017 Post 05-03-2017 Post 06-12-2017 2016 Post 10-01-2016 Post 05-03-2016 Post 06-12-2016 2015 [...] How can I do? I Tried width query_posts($args) but I can't order by a second field
Category: Web

query posts with selected post ids first

Is there a way I can get most recent posts with a couple of posts I specify by post ID listed first? According the docs, the order and orderby parameters may be passed as an array, so in theory I'm wondering if this could be possible. In MySQL query terms, it would essentially produce a result like SELECT * FROM wp_posts ORDER BY ID=12345 desc, ID=12543 desc, post_date desc where it returns post 12345, then 12543, then the rest ordered …
Category: Web

Display post in order of ACF checkbox?

I have a custom post type called ‘Skateboards’. Within the custom post type of ‘Skateboards’ , I added three checkboxes (filed type checkbox) with a field name of ‘skateboard_performance’ associated to the ’Skateboards’ custom post type via ACF. The values of the three check boxes are ‘Platinum’ , ‘Gold’ and ‘Silver ’. What I am trying to accomplish is to display the ‘Skateboards’ post type in order of ‘Platinum’ , ‘Gold’ and ‘Silver’. So all of the Skateboards posts marked …
Category: Web

WP_Query order posts by category

In a custom WP_Query I want to order posts by category. I mean that I want to show posts with term_id=1291 first and then show other posts. when I use two WP_Query , I cant use pagination. "edited" I tried this at first. I thought when I use post__in, wp_query ,keep posts order in post__in. $c_cat=$_GET["c_cat"] $query1 = new WP_Query(array( 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $c_cat, ) ) )); $query1_ids=array(); foreach ($query1->posts as …
Category: Web

Revolution Slider Orderby Two Custom Fields

I have create Revolution Slider which load the custom post type, Events. There are two custom fields, Event Start Date and Event End Date. I would like to display order by Start and End date. Because now only able order by Start date and if same Start date, then will order by Title. Here is what I found from Revolution Slider website: https://www.themepunch.com/faq/sort-options-post-based-sliders/ function modify_slider_order($query, $slider_id) { if($slider_id == 4) { $query['meta_key'] = 'event_start_date'; $query['orderby'] = 'event_start_date'; $query['meta_type'] = 'DATE'; …
Category: Web

Order posts by more than one variable (meta_key and publish date AND time)

At cascadeoc.org/results I have results sorted by a Custom Field, "event_date_results" which is the date the event happened (not the date the post was published). However, when there are multiple results from the same day, I'd like to further control post order by published date and TIME. How can I add this second orderby filter? Here's what I have: <?php $query = new WP_Query( array( 'post_type' => 'result', 'posts_per_page' => 100, //'paged' => $paged, 'meta_key' => 'event_date_results', 'orderby' => 'meta_value_num', …
Category: Web

Sorting posts by custom date fields (non standard date format)

I've inherited a website with a post type courses that has a custom field 'date-start', a Date Picker. Unfortunately the date start is stored as 'ddmmyy' and the ACF documentation implies that this code works with 'yymmdd' Now I can't change all dates to this format because there's lots of dependent code. So how do I get this query to work - to order the posts in order based on the 'date-start' custom field? It doesn't work with order as …
Category: Web

I Changed the Menu Order, But the Page Order Didn't Change on Front Page

First-timer here! I'm trying to change the order of pages on my boardgame webpage, as displayed on the top banner www.mangakagame.com . Basically, I've used "Edit" in the Dashboard and adjusted all the "order" attributes, but nothing changes. It's still using chronological ordering. The "Simple Page Ordering" plugin didn't do anything either. Weirder still, I tried to set one of the pages to "Private" but it still shows up in the banner! :/ It just links to an "Oops! That …
Category: Web

shortcode order for event custom post type

ok im working on a website using post type event with post_meta event_start_date, i created a shortcode and everything is displaying fine except for it displaying in order, it seems as its not displaying by using meta_key nor meta_value. this the page http://mixedbagnext.com/wordpress/events/ you'll notice the date order is wrong, i want it to display the most recent date first then the other dates following. side note im using more fields plugin to create post_meta and is set to date …
Category: Web

Sort posts by Date (DESC) and by Title (ASC)

Currently, the posts of my website are ordered alphabetically by title: /* Order Posts Alphabetically */ function prefix_modify_query_order( $query ) { if ( is_main_query() ) { $query->set( 'orderby', 'title' ); $query->set( 'order', 'ASC' ); } } add_action( 'pre_get_posts', 'prefix_modify_query_order' ); Now, I want to sort the posts alphabetically by title (ascending), but also by date (descending). Like this example: AUDI A1 Ambition 1.4 (posted in 01/01/17) AUDI A1 Ambition 1.4 (posted in 01/01/16) AUDI A1 Ambition 1.4 (posted in 01/01/15) …
Category: Web

About

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