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

Get post_meta of children and compare to current page ID

Here is the code that ended up working for me:

<?php
  $mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'menu_order', 'sort_order' => 'asc' ) );
  foreach( $mypages as $page ) {         
  $content = $page->post_content;
  $content = apply_filters( 'the_content', $content );
  $price = get_post_meta( $page->ID, 'price', true );
?>
<div class="service">
<h4><a href="https://wordpress.stackexchange.com/questions/126795/<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h4>
<div class="price"><?php echo $price; ?></div>
<p><?php echo $content; ?></p>
<p><?php
      $currentPageID = $page->ID;
  $child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent =2526 AND post_type="page" ORDER BY menu_order", 'OBJECT');
  if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild );
  $services = get_post_meta( $pageChild->ID, 'services', true );
      if (preg_match('/(^|,| )'.$currentPageID.'($|,| )/', $services, $matches)){
  echo "<a class="promotion-link" href="" . get_permalink("2526') . "'>A promotion is available for this service</a><br/>" ;
  //  echo "matches";
}
endforeach; endif;
?>

Related Posts:

  1. how to properly list child pages in sidebar?
  2. Get custom field value from Grandparent Page for Parent and Child Pages
  3. Given the page id, check if it has children
  4. How to get a list of all recently published child pages?
  5. WordPress get the child pages of current page
  6. Show siblings (if any) and parents
  7. List child pages of current page but limit to specific year
  8. Child page excerpt
  9. Create WordPress child page from page actions
  10. How to show child page without providing ID so it’s dynamic
  11. is_child() function
  12. Drop-Down Menu of Current Child Pages
  13. How to display childrens custom fields?
  14. Get WordPress Child Page IDs
  15. Displaying the first child page of the parent page
  16. Adding title and description to subpage’s featured image
  17. Show list of Child Post in Parent Post
  18. List subpages in order
  19. parent page grabbing wrong url for child pages – get_page_uri($pageChild)
  20. i want to get the parent id, only on parent -> child -> child page
  21. Get first level children of a page ID
  22. Only one parent page showing
  23. Create a list of pages excluding children of selected page
  24. WordPress Betheme: Unkown subheader image of a child page
  25. How to disable alphabetical sorting page
  26. Structure for calling child pages
  27. Child pages and sub-pages do not appear. Why?
  28. Add link to parent page in list of child pages
  29. Display child pages full template including the content
  30. List child pages, exclude the current page
  31. Listing Child Pages in Random order
  32. How to display child pages with in a limited child content?
  33. Display Tags of Child Pages
  34. Display the latest content from subpages of another page
  35. Limit the number of child page displaying
  36. Show the grandmother/father of the childpage
  37. How to Hard Set the Parent Page in Template
  38. Website parent child relationship
  39. Sanitizing integer input for update_post_meta
  40. Dealing with Many Meta Values, 30+
  41. Strategy to get post meta for use outside the loop
  42. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  43. Remove parent slug for child pages
  44. How to update single value in multi dimensional Post Meta?
  45. How to Update post status using meta data in Custom post TYpe
  46. Post meta checkbox becomes unchecked occasionally
  47. How to generate numbers indistinguishable for the IDs of the posts
  48. get_post_meta remains empty while looping all menu items and using the ID
  49. WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
  50. How to set YouTube video as featured image?
  51. Long Polling: Stuck in while loop
  52. Display custom field meta outside loop, site wide
  53. Widget: Custom Post Type Post Listing Dropdown on Admin Side
  54. Query_post($args)
  55. WP_Query with meta_query for children
  56. Sort custom meta column by other meta value
  57. How to duplicate entire custom post type
  58. Hide custom meta data if empty
  59. Child page menu in sidebar
  60. How to separate posts in loop?
  61. Custom post meta values reset by autosave [duplicate]
  62. How to get posts with a metadata numeric key greater than X?
  63. update_post_meta only updating on last loop of foreach
  64. WP API Response does not show my registered metadata
  65. Adding Custom MetaData
  66. How to add post meta in while loop?
  67. Problem with adding custom post type meta to header by plugin
  68. WooCommerce Bookings Plugin Not Saving Order ID
  69. How to echo value of a meta select box to the browser
  70. How can i get multi checkboxes value in metbox?
  71. saving/reading custom field value does not work – no value gets POSTed
  72. Display Meta Data with HTML?
  73. Group Posts By Custom Meta Value: Date
  74. How can I query for posts using a date stored in post-meta?
  75. Update Images after edit via php
  76. Something adding an excessive meta description
  77. Saving custom post types post_meta over REST-API fails
  78. how to query posts using value in meta post array
  79. Easy Image Gallery – Retrieve Serialized Data
  80. add_post_meta only adding 1 character
  81. WP update_post_meta link loop
  82. How to order posts by the user_login that corresponds to a meta_value (which is a user id)?
  83. Detecting top parent category fails on home page
  84. How to update post meta with xml data
  85. Show related (archive) month and year to post
  86. Allow iframe in custom meta box
  87. Datepicker altField and altFormat to save a new meta key/value in a post?
  88. Changing to different post type maintains the redirection?
  89. wordpress query making site very slow
  90. if condition from post_meta not working in save_post
  91. save all acf options in one meta_value [closed]
  92. How do I add the “orange counter” next to a Custom Post Type?
  93. Extend search query to search meta keys values based on search string
  94. I read the postmeta and update it without changing it, then move on to the next record
  95. Quering a post object based on another related post object
  96. How to create archive child pages with good Yoast SEO meta?
  97. Force post update with React
  98. How can I create Woodmart theme “linked variations” through REST API?
  99. How to append $metadata[‘sizes’] to metadata when using ‘wp_generate_attachment_metadata?
  100. Block Editor – Meta values not saved, meta changes to empty array on update
Categories child-pages Tags child-pages, post-meta
Contact Form 7: custom validation [closed]
Style of a theme

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
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 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