You’re setting $id = $post->ID;
outside of the loop for agent_type
posts, it’ll never match.
Anyway, if you’re not doing anything with the agent_type
posts that don’t match, just query for the one post you want by its ID:
$list_agent = get_post_meta( $post->ID,'ec_agents',true );
$args = array(
'post_type' => 'agent_type',
'p' => $list_agent
);
$agent_query = new WP_Query( $args );
while ( $agent_query->have_posts() ) : $agent_query->the_post();
echo get_post_meta( get_the_ID(),'_agent_phone',true );
echo get_post_meta( get_the_ID(),'_agent_email',true );
endwhile;
wp_reset_query();
Related Posts:
- meta_query with meta values as serialize arrays
- Order by multiple meta key and meta value [closed]
- WP_Query with checkbox meta_query
- How to grab metabox value in wp_query meta_query key
- Meta box dropdown of custom posts
- Custom Metabox data slow query on Admin init
- New WP_Query loop in admin causes problems
- Posts query according to meta box date
- create metabox to activate slider
- How do I add an item to the WP admin menu?
- wp list pages using meta box value
- Meta Box WP_Query array for showing items with a certain relationship
- Add metabox if there is at least one post available
- meta_query with meta values as serialize arrays
- update_post_meta() not updating
- Query by meta value (add a dropdown of all values)
- Wp Query sort order
- Saving custom fields for WP_Query to retrieve
- How to show all the associated posts with specific date of data metabox?
- display post multiple times based on array of dates
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Exclude post ID from wp_query
- Can I force WP_Query to return no results?
- paginate_links() adds empty href to first page and previous link
- Get array of posts from the current archive page loop
- Last post ordered by publish date using WP_Query on front page
- Meta Query with date and time on the same Day before given time
- In loop: posts have thumbnail AND other variables
- Add and in the header while looping over custom query in page template
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- Pagination not working on static page
- How can I create a WP_Query that returns posts where one meta_value
- Get posts from the Main site to sub site – WordPress MultiSites Network
- Query posts with more than 20 comments
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Get array of current post term ID’s
- Implementing an OR statement to wordpress wp_query
- How can i simulate “taxonomy__in” in query?
- Minimize database queries to user tables?
- How to make Meta Query case sensitive?
- Populate tax_query terms parameter with post term
- Orderby the sum of several numeric custom meta fields
- unable to retrive parent page information
- Site not getting correct featured image from my query
- wp_query ‘s’, search filter with pagination is not working
- Use more than one query, but prevent duplicates – at scale!
- Modify wp-query and sort by post meta key
- How to display an other custom post type in a different custom post type’s archive?
- Replacing raw database query to WP_Query
- Stale $GLOBALS[‘post’] after custom WP_Query empty result set bothers my template, whose fault is this?
- WP CLI can’t delete plugin related table
- Inserting HTML to close and open divs in WP_Query loops
- Change query from cat id to slug or name?
- Query only the posts with a post format of “audio”
- Display Current Post’s Position in Custom Taxonomy
- Using Wp_Query without the loop?
- WP Query with multiple tags by get the tags
- Custom WP_Query id
- Woocommerce pagination and result count after custom loop
- Orderby custom meta returns random order
- Include latest author posts with pagination in single template?
- How to querry for an item that saved in an array?
- get_post() is not returning correct value
- Intiger meta value with ‘>=’ returns posts with lower value
- Update query for wp_posts and wp_postmeta
- How to print term name inside wp post loop
- CPT category post/content is not showing on my page, Please review my coede
- WP_Query with page_ids in arguments without a result
- Advise on Templates for Custom Queries
- Query not sorting DESC
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Filter products on category AND tag
- meta_query – check for multiple meta values in key which holds an array of values
- How to sort wordpress posts already selected by WP_QUERY
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- WP_Query on custom key and value
- Set “editor” role to existing user
- how to get wp_query posts only first letter of alphabet A?
- How to mix two orderby-parameters into one ordered result
- Custom Post Type WP_Query with filters and search
- Merge wp-query and get_users
- WP_Query how to add a thumbnail to the first post from the last 5 posts?
- WP Query issue for multiple values
- Calling a function with WP_Query only ever brings the first result
- get last child post by wp_query
- WP_Query don’t working with fixed post_id and term_taxonomy
- How To Query All Attachment Images Found In Post Galleries
- WordPress meta_query not working
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Using orderby with 2 meta keys
- $wp_query when new WP_Query
- Unable to pass variable
- WP Query get posts by specific author IDs if one of several logged in authors
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- Edit WordPress loop, taxonomies, & filter
- How to display posts from a specific term first then another posts from another terms using tax_query
- How can I get taxonomy term name using term slug & post ID using build in WordPress function or class?
- new WP_Query with order args – no more distinction between categories
- How to make OR condition in WP_Query