WordPress has quite a few global variables to choose from which may help. For example, you can use the global $post
to get first post in the query.
global $post;
$my_meta_value = get_post_meta( $post->ID, '_another_meta_key', true );
Or you could reach directly into the $wp_query object posts array and grab the first post:
global $wp_query;
if( ! empty( $wp_query->posts ) ) {
$my_meta_value = get_post_meta( $wp_query->posts[0]->ID, '_another_meta_key', true );
}
Related Posts:
- Sort posts by category name and title
- ajax category filter
- Display posts the match taxonomy term linked from wp_list_categoies?
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Nested query inside Logical operator OR not working in meta_query
- SQL Statement generated by WP_Query not producing expected results
- WP_Query on different site in a multisite setup
- Best practice for multiple queries on page
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- How to user WP_Query to lower the number of queries
- Exclude post on loop by multiple meta key value
- how do i combine keyword search and taxonomy in a WP_query $args array Worpresss [closed]
- How to find out what “Blog pages show at most” is set to [duplicate]
- difference between $wp_the_query and $wp_query? & getting the values properly [duplicate]
- Ignore/Skip default value on orderby menu_order?
- WP_Query order by date in meta_value
- WP_Query pagination not working in admin area
- Custom Field sort not working (WP 3.8.1)
- Sanitizing search data for use with WP_Query
- How to search by a post and a category name on wordpress at the same time?
- What’s the point of the query_vars filter?
- Meta query with order by another custom field
- Get the Plugin Which Triggered a MySql Query in WordPress?
- How can I get an array of all IDs from the current queried object?
- Get Category Archive Template Name Dynamically
- How to limit WP_Query to one result on the loop?
- WP User Query get all authors with last name starting with specific letter
- Query post from all category with same tag on 1 pages
- How to correctly pass values to wpdb->prepare()?
- How to use filter hook “the_posts” with a function that refers to $this?
- Is there a way to include a post multiple times in the same query result?
- WP_Query, pre_get_posts and offset
- Multiple Search Terms WP_Query
- Filtering posts from different categories into different section by doing WP_Query only once
- Suggestions on making this query/code more performant
- Where to put meta Keys
- WP Query Args – Title or Taxonomy Value
- Slow WP_Query with ‘OR’ on meta_query
- How to filter a query by multiple meta keys and order by other meta keys
- Multiple Orderby’s using random order WP_Query
- using pre_get_posts for search results not found
- How to query for all posts that have a particular meta key?
- How can I override one post and make it display content for another post?
- Ajax future single post query doesn’t work when NOT logged in
- Exclude parent with child pages from WP_Query
- Co-authors list of all posts
- Get multiple users with meta value in one query and populate WP_User class
- get_posts always returning the same number of posts = 5
- WP_Query calls all posts?
- WP_Query Taxonomy categories filtering
- WP_Query: apply an SQL function to meta fileld value
- The best way to store variable across different widgets
- Assign a minimum result count for WooCommerce query shortcodes?
- WPQuery calling specific posts problem
- Retrieve data from wordpress db via input and put those result in dropdown
- How to use ‘WP_Query’ or ‘query_posts’ to display content in a descending order
- How to display specific ids of posts using wp_query?
- Filtering by multiple conditions in the loop
- Limit loop to future events
- Echo User Name from User with most comments of today?
- Custom wp_query differs on index page and category page
- Tax_Query using WP_Query not working
- WordPress Queries Not Working?
- How to stack name list in non-alphabetical order?
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- orderby ignored by wp_query
- $wp_query->found_posts not returning correct value
- How to make a post with certain taxonomy term display first before other post with only one query?
- Exception for excluding previously displayed posts in queries
- How do I compare the value of two taxonomies in a wp_query
- display ACF repater field in archive page
- Custom Taxonomy Archive Page to display either ALL listings or only from URL
- query hook parse_tax_query function takes no effect
- Meta query ignores multiple values of the key
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Query by meta key and order by another meta key value
- Get authors list and sort them by recent posts
- Custom filter from post meta
- Is there documentation for objects returned by WP_Query?
- Pagination not working in custom loop WP_Query
- Multiple wpostmeta.meta_key
- Custom post type loop error: Trying to get property of non-object
- Search Field that allows options of “Match any keyword” or “Match all keywords”
- Saving custom fields for WP_Query to retrieve
- Getting the last X posts, but in ascending order of time
- Modify query to exclude certain ids and certain parents and its corresponding children
- How to fix pagination for custom loops on front-page.php
- WP_Query with MetaQuery issue
- Cannot order by in WP_Query
- How to sort a WP_Query array by post_name after an array_merge();
- Comment count same for every post in homepage WP_Query
- new WP_Query based on average values of meta fields
- WP_Query breaks pagination
- wpdb LIKE request shows all database data
- Can’t seem to get an else statement correct? [closed]
- query_vars category_name only display one catgory out of multiple categories
- Incorrect posts displayed on category page
- How to get all post_id and meta_value using meta_key in wp_postmeta table
- How can I get taxonomy term name using term slug & post ID using build in WordPress function or class?
- Why does wp_query only display the most recent post when using order ASC?