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 id within comments loop

Note that it might be easier to use get_comments() here, since it’s defined as:

function get_comments( $args="" ) {
    $query = new WP_Comment_Query;
    return $query->query( $args );
}

If you need the comment url, within your foreach comment loop, you can use:

$comment_url =  esc_url( get_comment_link( $comment ) );

You can also get the post id from the $comment object with:

$post_id = $comment->comment_post_ID;

then you can use that to retrieve the custom post meta:

$property_address = get_post_meta( $post_id ,'imic_property_site_address',true);

To get the corresponding post permalink

$post_url = esc_url( get_permalink( $post_id ) );

Related Posts:

  1. WordPress loop by meta key that is an array? and how loop multiple arrays
  2. How to add post meta in while loop?
  3. Efficient way of querying for a “fallback” post?
  4. Using loop pagination on single.php
  5. Loop with slider (slider not loading)
  6. How to hide all child pages with post_query?
  7. How to sort posts based on the value (number) of a post’s metadata?
  8. Show css depending on activity type in BuddyPress activity-loop [closed]
  9. Sending data from custom inputs in WordPress comment form in the admin notification email
  10. Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
  11. Show wp_die if url form comment not emply
  12. Sort custom meta column by other meta value
  13. Why does my callback function not work with this custom filter hook?
  14. Customize Theme comment template to Insert VoteUp and VoteDown buttons
  15. Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
  16. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  17. Creating user status mode in WordPress
  18. Need help with Google drive API [closed]
  19. Iterate through posts based on array of categories
  20. get author_name from queried post
  21. Displaying Woocommerce Product Category in WordPress
  22. How can I add extra word in permalink when someone click download button?
  23. How to implement a rating and review system for WordPress custom posts?
  24. Increase offset while looping
  25. Blog posts repeat
  26. Ajax load more button for comments wordpress
  27. How to add condition in wordpress loop? [closed]
  28. Woocommerce : Can’t get product info in loop
  29. How to set variable, pass it to a partial file and remove it after?
  30. how to refresh div on template part?
  31. edit_comment_link is not showing for comment author
  32. Limit 1 global comment per minute
  33. Alert Bar section within WP loop is displaying even though there are no posts
  34. Create Page To Count Comments For Each Post In WordPress Site
  35. remove post that has no content
  36. Archive post by meta value + 24hours
  37. Display category name only once inside loop
  38. comments sorting incorrectly across multiple pages
  39. Commenting out unwated CSS/scripts in HTML with PHP
  40. Can’t find infinite loop cause
  41. Checking array against author id in loop
  42. How do I Turn This Into An if statement?
  43. WordPress update_post_meta updating with empty meta_value field [closed]
  44. wp-comments-post.php file returns a blank page
  45. php function to display commenter username or login
  46. Load wordpress content in other domain
  47. Genesis framework comments broken?
  48. How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
  49. Checkbox doesn’t stay checked, conten
  50. check if comment submitted was successful
  51. post thumbnail, conditions, else wont work
  52. Widgets in the loop if active
  53. Alter required message using comment form api
  54. List posts that don’t have a specific tag?
  55. Changing the_posts_navigation() html output
  56. Can we count the WordPress Loop
  57. Is it possible to retrieve all posts with a certain value for metadata?
  58. Syntax error when I try to insert my loop into an unordered list? [closed]
  59. WP_Query fails despite having 1 post
  60. Non-Closing PHP Query in WordPress Loop
  61. Add content after the first post in WP Loop
  62. wp_query get the 2nd post
  63. Loop stopped working
  64. How to get post ID in a Page?
  65. Custom Pagination is Broken
  66. Display an image if odd number of posts in grid
  67. WordPress comment submit button substitutes/options
  68. How to loop through all the attached images in a post, and get their url one by one
  69. I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
  70. How to list commenters and days since last commented
  71. PHP Warning: strip_tags() expects parameter 1 to be string?
  72. Output meta into arrays
  73. Querying Database with wpdb
  74. Store post content in a php variable and output them using for loop
  75. How to add div blocks after certain set of post
  76. Echo a shortcode div after every 3 posts
  77. How to avoid duplicates when creating recent network posts
  78. How to add text to the start of all comments?
  79. Does anyone know all parameters of get_comments()
  80. How to overwrite orderby with add_query_var
  81. What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
  82. Why in my theme I can’t see all the statics content under the posts?
  83. Appended comments but they show up above the content instead of below
  84. 2nd page displaying the exact same posts as my first page (minus the very first post)
  85. get comment data using comment id
  86. Removing the comment function within wordpress
  87. Is the 404 page automatically displayed if a loop returns nothing?
  88. update_post_meta only updating on last loop of foreach
  89. How do I remove a category from a wordpress loop>
  90. variable value disappears in a second loop
  91. Last class on last headline?
  92. Show recent posts starting at a specific number archive
  93. wp_delete_comment takes two tries to delete – then deletes all comments
  94. how to get serialized post meta
  95. get_the_ID() in the footer returns wrong value
  96. How to get the last category name of a child category?
  97. Change “No Comments” link to “My String” on Blog Post (Find Snippet in Code or use CSS, PHP Solution) [closed]
  98. How to use two meta_compare in an array?
  99. Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
  100. WordPress query undefined offset in loop
Categories PHP Tags comments, loop, php, post-meta
Adding wrapper elements in the_date() like in the_title()?
wp_get_attachment_image() not displaying post images even though wp_get_attachment_url() echo correct urls

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