Wordpress sort custom taxonomy posts by custom field value Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Wordpress query - Order by meta-field valueshow post titles below each category wordpressWordPress WP_Query: Display custom post type based on custom meta value, and also order on another custom meta valueShow posts from custom taxonomyhow woocommerce product get order by product tagWordPress taxonomy images plugin displaying all termsWordpress: Using post__not_in to exclude custom taxonomy categorySort terms on custom taxonomy by custom metadata (pre_get_terms)Get image post by taxonomy/category wordpressHow to attach custom taxonomy to a post in Wordpress?
How to translate "red flag" into Spanish?
Error: Syntax error. Missing ')' for CASE Statement
Retract an already submitted recommendation letter (written for an undergrad student)
Can I criticise the more senior developers around me for not writing clean code?
"Rubric" as meaning "signature" or "personal mark" -- is this accepted usage?
How to open locks without disable device?
How to use @AuraEnabled base class method in Lightning Component?
What to do with someone that cheated their way through university and a PhD program?
Protagonist's race is hidden - should I reveal it?
Additive group of local rings
Implementing 3DES algorithm in Java: is my code secure?
What *exactly* is electrical current, voltage, and resistance?
Passing args from the bash script to the function in the script
Trumpet valves, lengths, and pitch
Could moose/elk survive in the Amazon forest?
France's Public Holidays' Puzzle
c++ diamond problem - How to call base method only once
Seek and ye shall find
How would this chord from "Rocket Man" be analyzed?
What was Apollo 13's "Little Jolt" after MECO?
Split coins into combinations of different denominations
Would reducing the reference voltage of an ADC have any effect on accuracy?
What is /etc/mtab in Linux?
Justification for leaving new position after a short time
Wordpress sort custom taxonomy posts by custom field value
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Wordpress query - Order by meta-field valueshow post titles below each category wordpressWordPress WP_Query: Display custom post type based on custom meta value, and also order on another custom meta valueShow posts from custom taxonomyhow woocommerce product get order by product tagWordPress taxonomy images plugin displaying all termsWordpress: Using post__not_in to exclude custom taxonomy categorySort terms on custom taxonomy by custom metadata (pre_get_terms)Get image post by taxonomy/category wordpressHow to attach custom taxonomy to a post in Wordpress?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a custom taxonomy page that queries the custom post types attributed to that taxonomy, in my case the custom post type is "cars", and an example taxonomy page is "exceptional cars" or "convertibles".
On the taxonomy page "taxonomy-luxury-cars.php", I need to display the posts ordered by a custom field "display_order", but I cannot get the posts to display in the correct order.
Basically all I need is to insert an orderby "display_order" (custom field) before the "while have posts" loop, in to reorder the posts.
I have tried numerous snippets found online, but none work correctly.
Snippet 1
(only lists all posts "cars", but I need it for only the posts of the current taxonomy)
$posts = get_posts(array(
'post_type' => 'cars',
'posts_per_page' => -1,
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
Snippet 2
$terms = get_the_terms( get_the_ID(), 'luxury-cars' );
foreach($terms as $term)
$posts = get_posts(array(
'post_type' => 'cars',
'tax_query' => array(
array(
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
)
),
'numberposts' => -1
));
foreach($posts as $post)
echo get_the_title();
Snippet 3
$queried_object = get_queried_object();
$args = array(
'post_type' => 'cars',
'term' => $queried_object->slug,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => 'display_order',
'meta_query' => array(
array(
'key' => 'display_order'
)
),
'tax_query' => array(
array(
'taxonomy' => 'luxury-cars',
'terms' => array(
$queried_object->term_id
)
)
)
);
$query = new WP_Query($args);
while ( have_posts() ) : the_post();
...
wordpress while-loop custom-taxonomy
add a comment |
I have a custom taxonomy page that queries the custom post types attributed to that taxonomy, in my case the custom post type is "cars", and an example taxonomy page is "exceptional cars" or "convertibles".
On the taxonomy page "taxonomy-luxury-cars.php", I need to display the posts ordered by a custom field "display_order", but I cannot get the posts to display in the correct order.
Basically all I need is to insert an orderby "display_order" (custom field) before the "while have posts" loop, in to reorder the posts.
I have tried numerous snippets found online, but none work correctly.
Snippet 1
(only lists all posts "cars", but I need it for only the posts of the current taxonomy)
$posts = get_posts(array(
'post_type' => 'cars',
'posts_per_page' => -1,
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
Snippet 2
$terms = get_the_terms( get_the_ID(), 'luxury-cars' );
foreach($terms as $term)
$posts = get_posts(array(
'post_type' => 'cars',
'tax_query' => array(
array(
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
)
),
'numberposts' => -1
));
foreach($posts as $post)
echo get_the_title();
Snippet 3
$queried_object = get_queried_object();
$args = array(
'post_type' => 'cars',
'term' => $queried_object->slug,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => 'display_order',
'meta_query' => array(
array(
'key' => 'display_order'
)
),
'tax_query' => array(
array(
'taxonomy' => 'luxury-cars',
'terms' => array(
$queried_object->term_id
)
)
)
);
$query = new WP_Query($args);
while ( have_posts() ) : the_post();
...
wordpress while-loop custom-taxonomy
add a comment |
I have a custom taxonomy page that queries the custom post types attributed to that taxonomy, in my case the custom post type is "cars", and an example taxonomy page is "exceptional cars" or "convertibles".
On the taxonomy page "taxonomy-luxury-cars.php", I need to display the posts ordered by a custom field "display_order", but I cannot get the posts to display in the correct order.
Basically all I need is to insert an orderby "display_order" (custom field) before the "while have posts" loop, in to reorder the posts.
I have tried numerous snippets found online, but none work correctly.
Snippet 1
(only lists all posts "cars", but I need it for only the posts of the current taxonomy)
$posts = get_posts(array(
'post_type' => 'cars',
'posts_per_page' => -1,
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
Snippet 2
$terms = get_the_terms( get_the_ID(), 'luxury-cars' );
foreach($terms as $term)
$posts = get_posts(array(
'post_type' => 'cars',
'tax_query' => array(
array(
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
)
),
'numberposts' => -1
));
foreach($posts as $post)
echo get_the_title();
Snippet 3
$queried_object = get_queried_object();
$args = array(
'post_type' => 'cars',
'term' => $queried_object->slug,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => 'display_order',
'meta_query' => array(
array(
'key' => 'display_order'
)
),
'tax_query' => array(
array(
'taxonomy' => 'luxury-cars',
'terms' => array(
$queried_object->term_id
)
)
)
);
$query = new WP_Query($args);
while ( have_posts() ) : the_post();
...
wordpress while-loop custom-taxonomy
I have a custom taxonomy page that queries the custom post types attributed to that taxonomy, in my case the custom post type is "cars", and an example taxonomy page is "exceptional cars" or "convertibles".
On the taxonomy page "taxonomy-luxury-cars.php", I need to display the posts ordered by a custom field "display_order", but I cannot get the posts to display in the correct order.
Basically all I need is to insert an orderby "display_order" (custom field) before the "while have posts" loop, in to reorder the posts.
I have tried numerous snippets found online, but none work correctly.
Snippet 1
(only lists all posts "cars", but I need it for only the posts of the current taxonomy)
$posts = get_posts(array(
'post_type' => 'cars',
'posts_per_page' => -1,
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
Snippet 2
$terms = get_the_terms( get_the_ID(), 'luxury-cars' );
foreach($terms as $term)
$posts = get_posts(array(
'post_type' => 'cars',
'tax_query' => array(
array(
'meta_key' => 'display_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
)
),
'numberposts' => -1
));
foreach($posts as $post)
echo get_the_title();
Snippet 3
$queried_object = get_queried_object();
$args = array(
'post_type' => 'cars',
'term' => $queried_object->slug,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => 'display_order',
'meta_query' => array(
array(
'key' => 'display_order'
)
),
'tax_query' => array(
array(
'taxonomy' => 'luxury-cars',
'terms' => array(
$queried_object->term_id
)
)
)
);
$query = new WP_Query($args);
while ( have_posts() ) : the_post();
...
wordpress while-loop custom-taxonomy
wordpress while-loop custom-taxonomy
edited Mar 22 at 15:53
rainerbrunotte
asked Mar 22 at 14:03
![](https://i.stack.imgur.com/h3ggI.jpg?s=32&g=1)
![](https://i.stack.imgur.com/h3ggI.jpg?s=32&g=1)
rainerbrunotterainerbrunotte
470725
470725
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55301332%2fwordpress-sort-custom-taxonomy-posts-by-custom-field-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55301332%2fwordpress-sort-custom-taxonomy-posts-by-custom-field-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown