Simple with this reference:
https://codex.wordpress.org/Class_Reference/WP_Query
orderby should be meta_value
'meta_value' - Note that a 'meta_key=keyname' must also be present in the query.
Your key name should be one of the: CPU, OS, RAM ...
Also you can consider the WP_Meta_Query class.
https://codex.wordpress.org/Class_Reference/WP_Meta_Query
The Update
I got this result
Array
(
[0] => WP_Post Object
(
[ID] => 3233
[post_author] => 1
[post_date] => 2016-11-19 12:51:43
[post_date_gmt] => 2016-11-19 12:51:43
[post_content] => abc
[post_title] => Mac Air Pro 9G
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => mac-air-pro-3
[to_ping] =>
[pinged] =>
[post_modified] => 2016-11-19 12:52:19
[post_modified_gmt] => 2016-11-19 12:52:19
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://steve.com/laptop/mac-air-pro-1-copy/
[menu_order] => 0
[post_type] => laptop
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[1] => WP_Post Object
(
[ID] => 3232
[post_author] => 1
[post_date] => 2016-11-19 12:46:50
[post_date_gmt] => 2016-11-19 12:46:50
[post_content] => abc
[post_title] => Mac Air Pro 8G
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => mac-air-pro-2
[to_ping] =>
[pinged] =>
[post_modified] => 2016-11-19 12:52:47
[post_modified_gmt] => 2016-11-19 12:52:47
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://steve.com/laptop/mac-air-pro-1-copy/
[menu_order] => 0
[post_type] => laptop
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[2] => WP_Post Object
(
[ID] => 3231
[post_author] => 1
[post_date] => 2016-11-19 12:12:38
[post_date_gmt] => 2016-11-19 12:12:38
[post_content] => abc
[post_title] => Mac Air Pro 4G
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => mac-air-pro-1
[to_ping] =>
[pinged] =>
[post_modified] => 2016-11-19 12:52:57
[post_modified_gmt] => 2016-11-19 12:52:57
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://steve.com/?post_type=laptop&p=3231
[menu_order] => 0
[post_type] => laptop
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
Here is the content of the single-laptop.php file:
<?php
/**
* The template for displaying all single posts.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* @package microformats
*/
get_header();
// WP_Query arguments
$args = array (
'post_type' => array( 'laptop' ),
'post_status' => array( 'published' ),
//'s' => 'atom', // only if you need that
'nopaging' => true,
'posts_per_page' => '-1',
'ignore_sticky_posts' => true,
// order
'orderby' => 'meta_value',
'meta_key' => 'ram',
'order' =>'DESC',
/* you will need this only if
'meta_query' => array(
array(
'key' => 'ram', // or os, or cpu
'value' => '4', // meaning 4G of ram
'compare' => '>', // meaning only biggar
'type' => 'NUMERIC',
),
),
*/
);
// The Query
$query = new WP_Query( $args );
print_r($query->posts);
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'single' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<hr class="fat" />
<?php endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
laptopis not a category of Wordpress post. Also, I need to be able to filter by multiple custom fields, not just one, and I don't see from the code in the answer above how to do that. Thanks though!