Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to create meta fields with more than 1 relation?

A better approach would be to save two meta fields. One for the candidateID and one for the recruiter.

Then when you need to query the posts you should use the WP_Meta_Query with both meta fields and the relation argument set to ‘AND’:

$args = array(
  'post_type'  => 'opening',
  'meta_query' => array(
    'relation' => 'AND',
    array(
      'key'     => 'open_candidate',
      'value'   => $candidateID,
      'compare' => '='
    ),
    array(
      'key'     => 'recruiter',
      'value'   => $recruiterID,
      'compare' => '='
    )
  )
);

$posts = new WP_Query( $args );

Or if you have the post and need to find the candidate and the recruiter, you can just use:

$candidateID = get_post_meta( $post_id, 'open_candidate', true );
$recruiter = get_post_meta( $post_id, 'recruiter', true );

This hasn’t been tested but it should work.

Codex reference for WP_Meta_Query: https://codex.wordpress.org/Class_Reference/WP_Meta_Query

Related Posts:

  1. How to share category taxonomy with custom post type (The Event Calendar plugin)
  2. Query Posts by Custom Field ‘Price’
  3. Custom Taxonomy in plugin and template
  4. Update Multiple Post Meta for the Same Post In One call?
  5. How to make a list of companies’ information and display them to user, using custom post types and a custom taxonomy?
  6. Add .html extension to custom post type taxonomies
  7. Comparisson between date() and a date from wp_postmeta
  8. Show the “ratingValue” and “ratingCount” values ​of KK Star Ratings Plugin
  9. Updating post meta for custom post types
  10. Why is this custom taxonomy showing in the database?
  11. How can I add a custom meta value on file upload?
  12. remove custom taxonomy metabox form custom post type
  13. How to Build a Movie Library in WordPress 3.x
  14. Get product attribute for Simple product in WooCommerce
  15. Custom Post Type causes Page Not Found
  16. How to get custom field image url of specific size
  17. How to delete terms on plugin deactivate?
  18. How do I add advanced custom fields / meta fields to Elasticsearch? [closed]
  19. How to show category images (from plugin) on a regular page (page-example.php)?
  20. Woocommerce custom shared taxonomy
  21. taxonomy_template filter do not loads custom taxonomy template properly
  22. Set attached to state
  23. Plugin allowing for artists, events and venues
  24. How to change ID of an attachment in wp_posts and its related tables correctly?
  25. Add multiple attributes to product from php
  26. How to add rewrite rules and pagination to retrieve attachments files?
  27. custom taxonomy and custom post type url conflict
  28. Make the checkbox meta field checked by default
  29. Show Heirachy of categories in WP Download Monitor
  30. Custom Taxonomy Tag Search
  31. Add custom taxonomy to title tag [closed]
  32. Possible to replicate economist.com’s debate section in wordpress? [closed]
  33. Where to hook my plugin’s action
  34. Is there a filter for get_post_custom()?
  35. dynamically generating plugin syntax
  36. WP plugins for building a database?
  37. Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
  38. Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
  39. WordPress category add image field
  40. Where (or when) should I register a new taxonomy?
  41. Limit Number of Taxonomy Terms (Images) Displayed
  42. Widget for adding HTML markup to a page
  43. How I can get custom field’s current value?
  44. Want wp_get_post_terms return in arbitrarily order, how to do?
  45. Create digital-virtual-downloadable WooCommerce products from the frontend using Gravity Forms? [closed]
  46. List taxonomy terms for post as checkboxes
  47. Help to Create a Simple Plugin to make a post
  48. Adding category base to url in custom post giving 404?
  49. Display posts by alphabetical order
  50. get_post_meta shortcode returns empty field
  51. Add an action based on custom post meta field
  52. how to auto random increment for post view
  53. Rewrite/Change custom taxonomy slug
  54. Custom Taxonomy is Missing (Or Limiting) Items
  55. How to securely controlling data without keeping it in postmeta?
  56. Cannot view Custom Post Type no matter what I try
  57. “Enable Media Replace” plugin does not update serialized object in WPMeta
  58. Custom Field used to allow a Free Story; no longer works
  59. Performance considerations – postmeta table versus new table for custom posts with foreign keys?
  60. Get and Update Most Meta Value as an array in HTML form
  61. Only return taxonomies that are linked to a category & product
  62. Why is my custom taxonomy image not displaying?
  63. Show custom taxonomy in theme
  64. Taxonomy question
  65. Taxonomy Category Icon on index page
  66. Get only selected custom taxonomy
  67. Get value from an input field and pass into update_meta_data as $meta_value
  68. How to get post that has non zero or greater than zero meta value
  69. Delete postmeta when uninstall/delete plugin
  70. Get custom term link archive with prefix
  71. Same Title on two different post type with single custom taxonomy
  72. How can I make my plugin display custom post meta data on the front end?
  73. Add “selected” class to custom taxonomy dropdown search
  74. “Tree view” for wp_dropdown_categories() markup
  75. Save selectlist value (taxonomy) in wp:wp_set_object_terms
  76. Is saving multiple options or saving multiple items in one option better?
  77. Show similar category portfolio items?
  78. CPT-onomies CPT_TAXONOMY->get_terms extremely slow with 6K posts
  79. Storing values in Post Meta vs new tables
  80. How can I add the custom taxonomy categories to the posts and pages?
  81. Is there a way to add a custom input field for every taxonomy term in WP post editor?
  82. Award points if a specific custom taxonomy is selected – Cubepoints
  83. Add meta tags with a plugin?
  84. WordPress User Frontend Editing Custom Fields
  85. How to list the categories by custom taxonomy created?
  86. wordpress last all added get meta value by post id
  87. Get post id in Post Page within Wp-admin
  88. Output plugin post like system count [closed]
  89. ACF Taxonomy Object term Null [closed]
  90. getting image alt text via ACF plugin in WordPress [closed]
  91. Display Custom Post Type and Custom Taxonomy Data on Front End Using Only a Plugin
  92. Update post meta Rest Api
  93. how to add meta for order in woocommerce
  94. Failed to update a post when I add a taxonomy to it
  95. Create a custom taxonomy’s term form
  96. How to disable Yoast meta description for all pages
  97. Force post update with React
  98. How do I know if an archive correspond to a custom post type taxonomy?
  99. How to Display News in a Timeline with Headline, Category, and Time?
  100. Query Custom Post Types on Available Dates
Categories plugins Tags custom-taxonomy, plugins, post-meta
Shortcode and WP query using category attributes
add_action in wp_head accessible from class

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress