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. How can I clone/copy all fields (post and meta) from parent CPT post to child (with synced fields?)
  40. How do I retrieve the slug of the current page?
  41. Query all posts where a meta key does not exist
  42. wp query to get child pages of current page
  43. Most efficient way to get posts with postmeta
  44. How to only display posts whose meta_value field is not empty?
  45. Get posts by meta value
  46. Can the Next/Prev Post links be ordered by menu order or by a meta key?
  47. what is the correct way to compare dates in a WP query_posts meta_query
  48. How to hook update_post_meta and delete_post_meta?
  49. Explanation of update_post_(meta/term)_cache
  50. How to extract data from a post meta serialized array?
  51. Can I exclude a post by meta key using pre_get_posts function?
  52. Post meta vs separate database tables
  53. Advanced search form with filters for custom taxonomies and custom fields
  54. How to update custom fields using the wp_insert_post() function?
  55. How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
  56. Can wp_query return posts meta in a single request?
  57. order by numeric value for meta value
  58. Attaching taxonomy data to post with wp_insert_post
  59. Passing error/warning messages from a meta box to “admin_notices”
  60. Add “upload media” button in meta box field
  61. How to save an array with one metakey in postmeta?
  62. WordPress is stripping escape backslashes from JSON strings in post_meta
  63. Display Yoast WordPress SEO title in archive template
  64. Why WordPress choose data serialization over json_encode?
  65. Get parent page url to show up when it is in child pages
  66. How to make search include data from wp_postmeta?
  67. Meta query with boolean true/false value
  68. How can I get the post ID from a WP_Query loop?
  69. Why are simple updates to wp_postmeta’s “_edit_lock” so slow?
  70. How to check if post meta key exists or not in wordpress database
  71. Custom post meta field effect on the performance on the post
  72. Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
  73. Check if is on child-page of a particular page
  74. How to get custom post meta using REST API
  75. How do I query for posts by partial meta key?
  76. Difference between meta keys with _ and without _ [duplicate]
  77. Use REGEXP in WP_Query meta_query key
  78. Get post with multiple meta keys and value
  79. Correctly delete posts with meta and attachments [duplicate]
  80. Orderby meta_value only returns posts that have existing meta_key
  81. What is the index [0] for on post meta fields?
  82. Order by meta value or date?
  83. A check for if is parent page, if has children, if has grandchildren
  84. What is “meta_input” parameter in wp_insert_post() used for?
  85. How to hook a filter to catch get_post_meta when alternate a custom field output?
  86. How to update_post_meta value as array
  87. How to add category to: ‘wp-admin/post-new.php’?
  88. Adding meta tag without plugin
  89. Filtering posts by post meta data
  90. How to enable revisions for post meta data?
  91. What’s the point of get_post_meta’s $single param?
  92. How to use update_{$meta_type}_metadata filter to modify meta value
  93. WordPress retrieving meta data for all custom post types in list view
  94. The “_encloseme” Meta-Key Conundrum
  95. What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
  96. Can I have two child pages of different parents with the same name?
  97. Save camera info as metadata on image upload?
  98. Best way to programmatically remove a category/term from a post
  99. Order by optional meta key?
  100. How to edit a post meta data in a Gutenberg Block?
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
  • 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