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

Display articles related to a custom field on a page

If I understand well, you have a page template, and you want to use this page template as a category archive.

The term to show is in a page meta field with key ‘cat_page’.

If I’m right, in this page template use:

the post(); // being a singular page the 'while' stuff is useless
the_content(); // this will show the page content

$cat = get_post_meta( get_the_ID(), 'cat_page', true ); // get the category to display

if ( $cat ) { // if category is setted in page custom field
   $query = new WP_Query( 'category_name=" . $cat ); // run the custom query
   while ( $query->have_posts() ) { $query->the_post(); // run the custom loop

     // your post loop code goes here

   }
   wp_reset_postdata(); // reset the post data after the custom query
}

Pleas note that to make this work in the custom meta "cat_page' you should put the category slug (not the category name).

Related Posts:

  1. How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
  2. Do I need to use The Loop on pages?
  3. Get ID of a page containing secondary loop in content
  4. Is including the loop necessary for page.php? [duplicate]
  5. When and Why is is_singular(‘my_cpt’) true while in_the_loop() is false?
  6. loop not showing up when using a custom page template
  7. Custom page template
  8. Getting page ID inside loop
  9. How to add “time” data this?
  10. Get Pagination (WP-PageNavi) not to work
  11. Loop and Page template : my WP_query don’t take args
  12. Create a loop that gets pages with their template
  13. Running a loop with a custom query string on a custom page template
  14. Next and Previous loop
  15. How to load all pages into one page with their templates
  16. Custom Loop Using Shortcode in Custom Page Template
  17. Do I need to use The Loop on pages?
  18. Page-loop is looping content from custom loops on the same site. How to avoid that?
  19. How to hook into container
  20. Multiple get_posts() queries on one page
  21. Output meta into arrays
  22. value of metadata is null wrong use of if statement
  23. Sending mail not working correctly
  24. using update_user_meta to rank users
  25. Print the whole page?
  26. excerpt not showing up
  27. get_post_meta printing empty fields, but it shouldn’t be
  28. Custom Header added within Dashboard pages, is this possible with custom template files?
  29. Duplicated tag in loop
  30. get the value for ALT is we check to see if an actual ALT value is set, if not we use the caption and if no caption is set we use the title
  31. Check value of post meta within IF statement
  32. My WordPress installation doesn’t load correct template
  33. Best way to check if a post with specific meta exists
  34. WP update_post_meta link loop
  35. Humanmade | Custom meta box class: How to display a repeatable meta box group?
  36. get_template_part() to render single page Theme
  37. Stuck with conflicting loops on page template
  38. Same Loop on Multiple Pages
  39. Loop not showing up on page template
  40. Custom Page Template and Category Exclusion
  41. Display all posts in a page code for template
  42. Jquery Slider for profile template
  43. Get excerpt using get_the_excerpt outside a loop
  44. Should I use loop in the single.php file?
  45. wp_list_categories: get latest featured_image of category
  46. get_the_foo() in the loop – does it perform another query?
  47. Exclude filter on front page
  48. category__not_in — anyway to use category name instead of id?
  49. Check if date of post is yesterday
  50. Exclude first 2 posts with meta_key from loop
  51. Fix inefficient loop breaks post.php on form submit
  52. Make a custom loop inside single.php with pagination
  53. Why do I get `Call to a member function have_posts() on a non-object `? [closed]
  54. Pulling current post/page data into header.php
  55. How to split a loop into two columns
  56. Category Ajax call
  57. Transient loop issue
  58. popular post weekly and monthly
  59. WordPress Loop inside Loop?
  60. Get single post from tags array
  61. Apply an Incremental Counter in an Array Function
  62. Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?
  63. Using Javascript for Looped Content
  64. Making a query to the DB using same parameters of loop
  65. Variable not being passed into WordPress loop
  66. Exclude duplicated $sticky post from combined loop content
  67. WP Loop. If featured image is a panorama (3:1 ratio) execute some code
  68. Trying to get property of non-object in shortocde
  69. How to Loop with the final result formatted differently?
  70. Tags on page (not post) returns nothing – why? Improved clarified question!
  71. Include future posts in tags and in search
  72. Hide Page Title with Post Meta
  73. current-user_can not working in loop
  74. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  75. Show terms in archive page
  76. Multiple loops for plugin
  77. Static Website No Titles But Still Nav
  78. Loops for cat links not looping for wordpress site
  79. How to save HTML data into SQL post_content column
  80. Sort posts according to a numeric value entered with ACF
  81. wp_get_attachment_url not fetching URL?
  82. How to get all multi-select user meta values and add them to an array?
  83. How to resolve a reload loop issue in the frontend when logged in to WordPress multi-site backend admin area
  84. Excerpt isn’t working or am I missing something?
  85. Can I temporarily disable global $post?
  86. Shortcode for pulling specific Post Title outside loop when ID is passed in
  87. Show a list of user posts in the user admin page
  88. Efficient way of querying for a “fallback” post?
  89. Infinite Loop after Genesis Theme Upgrade
  90. WordPress loop only displays 5 articles max?
  91. Placing the content of one post in two side by side columns, newspaper style
  92. trying to write a variable into a wp_query, need help!
  93. Pass WP post content to a jQuery plugin (Fancybox)
  94. Showposts doesn’t show the number of posts indicated
  95. Using in_category for non standard loops
  96. Use Loop or direct database query?
  97. How wp maps urls into files
  98. Display Featured Image
  99. AJAX in wordpress theme loop
  100. Duplicate post problem
Categories loop Tags loop, page-template, post-meta
Get result from Custom Field in Custom Post type
How to fix pagination for custom loops?

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