Meta Queries are nested arrays. See the WP_Query section on meta queries.
Option 1
Use meta_key
and meta_value
directly in the query arguments, not as a meta query.
$student_query_args = [
'post_type' => 'student_list',
'post_status' => 'publish',
'posts_per_page' => 100,
'order' => 'DESC',
'meta_key' => 'program_id',
'meta_value' => 5317,
];
Option 2
The meta query approach. If you’re adding multiple you would need multiple arrays. The default relation is AND
but we’ll supply it for clarity:
$student_query_args = [
'post_type' => 'student_list',
'post_status' => 'publish',
'posts_per_page' => 100,
'order' => 'DESC',
'meta_query' => [
'relation' => 'AND',
[
'key' => 'program_id',
'value' => 5317,
],
],
];
Related Posts:
- Using OR conditions in meta_query for query_posts argument
- How to update a custom post title from a front-end form using ACF fields?
- How to add a custom field to quick edit
- Gutenberg First Block on Page Conditional?
- Using meta_query and custom fields within pre_get_posts to return posts within a numerical range
- Set default date in datepicker of an advanced custom field
- How to order by just the Time Field in Advanced Custom Fields
- Using Gutenberg parse_blocks Function With ACF Custom Blocks?
- ACF get field label in custom code
- How to customize a divs background dynamically using Advanced Custom Fields Plugin?
- How to update custom taxonomy meta using ACF update_field() function or any other wordpress function
- Thumbnails generated from PDF in the “Media” section – how to show them in theme template?
- Post Object field orderby (Advanced Custom Field)
- How to count ACF Flexible Content Rows?
- How can I track and output when a field is updated? (currently using Advanced Custom Fields)
- ACF Custom validation message not showing up
- How to write PHP array to render JSON-LD Markup for Job Postings, with ACF
- Is it safe and good practice to use do_shortcode to escape?
- Post edit – Media Library – Only get images from current post
- Output comma with get_field in Advanced Custom Fields [closed]
- Gutenberg on an ACF options page
- Changing a specific value inside a complex repeater/flexible content field (ACF)
- Add up values from ACF number field
- Bulk-Update Custom Posts
- Group ACF repeater fields from differrent posts
- How to get custom fields in a post when published
- Get all custom fields with wp’s get_posts()
- How to populate a parent page with its child subpages and associated templates
- Find the first occurrence of a custom field
- ACF Add fields values to newly inserted post [closed]
- Programatically re-order images in the ACF gallery add-on. Orderby Title, ID, etc
- Use ACF select field to add a class to div inside a flexible content layout [closed]
- ACF Relationship – Limit to specific pages
- Website goes down while importing backup (Internal server 500)
- Display total unique custon field results
- Advanced custom fields – pulling data in from another page
- ACF: If field contain a specific value, update value in another field programatically
- how to load random related posts with specific custom fields?
- ACF – Pick first or second value from comma separated values
- Displaying user data within ACF relational field (user type)
- ACF Image field not displaying in WordPress with Visual Composer [closed]
- Query and display only by first letter of the get_field value
- How to acquire an ACF image using get_previous_post and get_next_post
- ACF checkbox array is returning numbers, not labels [closed]
- Building large multi-section pages with Advanced Custom Fields
- Showing a post depending on the Custom Field value
- Advanced Custom Fields – category image
- Widget Code / Advanced Custom Fields / Elementor
- How can I apply an ACF field to a single custom post if it refers to the taxomy of that post type in the rules?
- ACF: Update field value based on value of another field
- Getting “Years Only ” from ACF Date Picker field to Hidden filed in the fields group
- How to show related post having same relationship filed under single CPT?
- Prevent other hooks from firing after wp_update_post() outside of editor
- Where to place CSS if add a new layout to FLexible Content Template
- Trying to update repeater field (ACF) dynamically with data from Contact Forms 7
- Get title color from category custom field
- WP Cron Working, but Function Not Working
- How to get a product’s Custom Fields in a different template file?
- Explore custom posts (CPT UI & ACF) database from WP UI
- pre_get_posts hook not targeting search results page query
- ACF – get custom taxonomy term image field
- ACF group field disappeared after deployment using deployer script
- get the title of a relationship field
- ACF Dynamic select not showing data
- Modification of RSS feed is not consistent
- How to call ACF field in functions?
- Multiple orderby date arguments
- How to use WP Backery on Wysiwyg ACF
- Looking for a javascript callback action to re-initiate a custom slideshow in gutenberg
- Advanced Custom Fields Gallery and Flex Slider [closed]
- Help using an array in ‘exclude’ key of another array
- Create Shortcode for php code in functions.php
- ACF: Updating gallery field doesn’t work in backend
- Build table using Advanced Custom Fields
- Pulling author name via $_GET parameter
- Front page showing ACF only once, is that solvable to show the ACF per post? [closed]
- Srcset incorrect with Owl Carousel and ACF?
- Rearranging Content After Blog Post
- Advanced Custom Fields – Google Map Won’t Render Unless Variable Dumped
- Add column and acf field content for cpt
- Can’t get ACF repeater data in category template
- Call the cropped image of a custom field in the theme
- Relationship field problem: Uninitialized string offset: 0 in
- ACF iterating past the while-loop, defining a max number to loop
- Displaying page list and a custom field
- Gettext for custom field checkbox values
- How to add admin functionality to allow ability to choose different field group to display on webpage using Advanced Custom Fields?
- Separate [Advanced Custom Field] values by commas
- Multiple loop issue – pull one featured and then continue the loop
- Advanced custom fields – If/ while field problem
- Check if meta_key exists in wp_list_pages
- ACF + WPML: How to translate date fields?
- ACF orderby not sorting dates correctly [closed]
- How do I convert an ACF field from a string to an integer?
- Using ACF custom field for custom post type to order categories
- PHP calls to custom fields not being made. Query seems to be blocking them
- How can i get custom field to apear on my wordpress admin area (post_type)
- Same ACF Relationship field for multiple Post Options sub-pages?
- Advanced Custom Fields – Issue with Slick Slider in ACF v6 Block
- How can I update an ACF field in a repeater on post save?