The query_posts
is only useful when you actually know what you are doing.
Base on the info you provide this should work for you :
$the_query = new WP_Query(array(
'post_type' => 'your_cpt',
'posts_per_page' => -1,//get them all
'meta_key' => 'field_4',
'orderby' => 'meta_value',
'order' => 'DESC'
));
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while( $the_query->have_posts() ) : $the_query->the_post();
$class = get_field('field_4');
?>
<li <?php echo $class; ?>>
<a href="https://wordpress.stackexchange.com/questions/287546/<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data ?>
Related Posts:
- Display List Of Posts Containing a Relationship Field Value [ACF]
- Using OR conditions in meta_query for query_posts argument
- ACF Relationship Field Search Filtering [closed]
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- WordPress meta_query and order by custom field
- Revolution Slider Orderby Two Custom Fields
- meta_query with array as value
- query posts in functions.php and update a field
- Minimising number of queries on a page when using Advanced Custom Fields
- Query Posts depends on custom field inside repeater field using acf
- ACF Relationship + WP Template Parts
- Minimising Database Queries when using Advanced Custom Fields
- ACF – Get lowest & highest value from field
- If two first numbers exist in wp_meta_query value
- WP_Query meta_query >= date
- get_posts – find out if querystring was crap and fallback is used
- How To Fix WP Query Returns Results But Shouldn’t?
- ACF Date Based wp_query
- Multiple taxonomy And acf filter group by
- Custom query based on meta key – Reduce three states to two in results?
- Include custom field in Ajax search WordPress
- What is the random string I am seeing when I use get_query_var?
- Any number in meta key (wp query)
- How do I run through a WordPress loop called from a filter function?
- How can I display a custom field from all posts and order them individually from their parent post
- Is there a way to work with a specific the_field from an already queried post? [closed]
- How to Union two different conditions in one WP_Query
- Excluding pages in WP_query using ACF
- How to do a wp_query with two acf-fields, sorting on one of them
- Using Advanced Custom Field for file upload, how do I load the file url
- Multisite wp_query & switch_to_blog issue
- Stuck in the query loop
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- WP_Query with meta_query dosen’t return results
- wordpress ajax relationship query
- how to access query string in wordpress?
- Is there a better way to pull in custom content without querying posts?
- Include post content of linked posts in search
- WP User Query with Custom Fields and Search Results
- ACF accessing a field from the query, but not in post
- filter wp_query result with custom field values
- WordPress Query String: get_posts(‘cat=5’) vs WP_Query( ‘cat=5’) vs URL: /site/?cat=5
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Merge 2 custom post type posts and taxonomy terms and sort ascending
- Add ACF field in a query
- JSON – Create rest api endpoint for Advanced Custom Fields
- Custom query filter by ACF date custom field
- Get a list of ACF Repeater-Fields as array
- WordPress dynamic AJAX query
- WP Query orderby ACF boolean values and ACF field value
- Optimising WP_Query with ACF Fields
- Order WP_Query by meta_key priority when ‘OR’ relation used for multiple meta values
- Multi-layered WP_Query
- Oxygen Repeater Advanced Query
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- Nearby locations using Advanced custom fields, maps?
- WP_Query – display posts by custom field and order by another
- WP_Query for distinct meta values
- Group Product Types
- WPQuery Date and ACF
- Excluding posts from search results page with meta query not working
- Populate select list with meta values from all posts of a Custom Post Type
- Form checkbox value going to dynamic URL
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- WP Query by variable custom field
- create custom shortcode wp and put php code in
- Query for getting posts with their custom fields data in WordPress
- Why does my output of get_the_ID() change after a wp_query?
- How to get taxonomy image attached to a Post Type WordPress
- How to rearrange posts based on input field values added by WordPress “Advanced Custom Fields”
- WP Query with meta queries
- Custom query showing all acf field values instead of the one searched
- WP_Query, ACF field and array
- Pre get posts sort by meta key returns no results if meta key does not exist
- How to query wordpress with array of meta_values?
- ACF query-pass field value
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- Limit default Search query to post_title
- ACF: using two loops, the_field returns field content from another loop
- Multiple wpostmeta.meta_key
- Get posts meta_query by repater field
- How can I modify standard search query to include also ACF custom fields values?
- Wrap group of wp query posts to parent div by date/year
- Object of class WP_Query could not be converted to int inside shortcode
- Wrote a WP Cron Plugin and it triggers a fatal error upon activation
- Issue in If else condition [closed]
- Can’t get the_content to show
- Geo location query inside wp_query?
- The sorting of posts by a meta_query with two keys fails while separated as single queries it works
- Get the type of an advanced custom field (ACF) in a WP_Query loop [closed]
- Query posts filter not working
- Creating array to compare custom field values
- Display all custom meta field values from the database using ACF Repeater
- Output ACF field dynamicaly within a taxonomy loop [closed]
- Get posts using multiple values from ACF checkbox as meta query wordpress
- I want to place a post before all others from an ACF boleen field
- How do I subquery with custom meta fields?
- Best performance for use Custom Field in WP
- Use value from meta key array for use in WP_Query
- WP_query shortcode inside acf Repeater breaks the repeater loop