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. Wishlist Icon in Divi Blog module (loop)
  43. How to fix pagination for custom loops?
  44. Jquery Slider for profile template
  45. Counting the posts of a custom WordPress loop (WP_Query)?
  46. if ( is_home() && ! is_front_page() )
  47. Get excerpt using get_the_excerpt outside a loop
  48. Get post content from outside the loop
  49. Why should I put if(have_posts()), is while(have_posts()) not enough?
  50. Getting only direct child pages in WordPress with get_pages
  51. Display featured products through custom loop in woocommerce on template page
  52. Split Content and Gallery
  53. How to get Author ID outside the loop
  54. How can i display the content in plaintext
  55. Redirect loop when trying to login to /wp-admin/ [duplicate]
  56. How to split a loop into multiple columns
  57. Is it necessary to reset the query after using get_posts()?
  58. Is there any difference between the_title() and echo get_the_title()?
  59. AJAX with loop filtering categories
  60. Remove the Homepage Query
  61. remove tags from the_content
  62. the_title() shows title of the first post instead of the page title?
  63. How to force excerpts / teasers in the loop
  64. Retrieve each widget separately from a sidebar
  65. Why am I being limited to ten posts on a custom loop?
  66. Ways to have multiple front-page.php templates that can be swapped out?
  67. Should I use loop in the single.php file?
  68. A search for ‘0’ returns results
  69. Why do themes rely on “The Loop”?
  70. Display all posts from specific categories on a page
  71. How to return loop contents
  72. Using the Loop to show all levels of subpages under a parent page? Halfway there
  73. Cleanest Way to Select Every Second Element in a Loop?
  74. Insert image or ad script after 3 posts using the loop
  75. Get date of last update outside of loop
  76. Pagination not working on home page
  77. Child Pages Loop
  78. How to place comments_template(); outside the loop?
  79. Multiple Loops Homepage?
  80. How to Change Loop to Order Posts by Views (using wp-postviews plugin)
  81. how to upload image using wp_handle_upload
  82. Avoiding using a loop to access a single post
  83. Strategy to get post meta for use outside the loop
  84. How to get the first image gallery of a product in woocommerce in a loop
  85. Get post by page name or slug
  86. save_post + insert_post = infinite loop
  87. Loop.php vs looping inside template file
  88. Custom Loop and Infinite Scroll
  89. Query Custom Meta Value with Increment
  90. Loop that displays PARENT PAGE & CHILD PAGE & outputs GRANDCHILD PAGE title and content
  91. is_home, and is_front_page conditional problem
  92. Is `query_posts` really slower than secondary query?
  93. Are there any scenarios where the query_posts may be used?
  94. the_content and wp_link_pages
  95. How can I create an alternative home page?
  96. Adding ‘current_post_item’ class to current post in the loop
  97. How do I get the attributes of a short code from a post?
  98. How can I custom order the results from wp_list_categories?
  99. ACF Repeater loops and resets – where is the reset_rows() documentation? [closed]
  100. WooCommerce Product Page Loop – Output All Product Thumbnails
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
  • 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