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

How can I setup custom templates for a meta-data query

There’s the core function add_*/get_query_arg() that you can use to append stuff to the query and retrieve it.

So simply add a link somewhere, that points to your custom post types single.php template

single-{$custom_post_type}.php

Then append the query arg which would be ?wpse_meta_key=wpse_some_val and then do a switch on top of your template:

if ( 'wpse_some_val' === get_query_arg( 'wpse_meta_key' ) )
{
    get_template_part( 'special_query_template' );
}
else
{
    // do default stuff
}

Related Posts:

  1. How to include template according to meta post value
  2. get_post_metadata() undefined when used in loop in RSS template
  3. Mysterious template change after database import/export
  4. Add default meta data to a page/post template
  5. How to use Class in Java?
  6. Get name of the current template file
  7. How do you find out which template page is serving the current page?
  8. How to change the default registration email ? (plugin and/or non-plugin)
  9. How do I get the size of an attachment file?
  10. Is there any way to use get_template_part() with folders?
  11. Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?
  12. How can i change email template for new user
  13. Any advantage to using get_header() over include(‘header.php’)?
  14. Enable page templates. How?
  15. Is it possible to override the result of get_template_part()?
  16. Use [embed] filter in template files
  17. What’s the purpose of the paged.php file?
  18. How do you access the Product Short Description in a WooCommerce email template? [closed]
  19. Prevent comments_template() to load comments.php
  20. Is there a way to list all used/unused WP templates?
  21. Page editor missing Templates drop down
  22. Print WordPress template filename(s) for debugging
  23. How to force TinyMCE in WordPress to replace newlines with tags and not with  
  24. How to find the posts page (home page) programatically
  25. WooCommerce: Change template for single product page
  26. View WordPress page template usage (or unused)
  27. How to edit contents of dynamic_sidebar()?
  28. How to check if a shortcode exists?
  29. Where is get_header(‘shop’) file in Woocommerce templates
  30. Custom templates folder
  31. What is the link to my default “archive” page?
  32. How to get slug of current category in taxonomy template?
  33. How to show a under construction page for a domain but still be able to work on index.php?
  34. Change the name of the ‘Default Template’
  35. Customizing get_the_excerpt() to specific length and “Read More” output.
  36. How to Rename a Template File?
  37. get page templates
  38. Echoing Elementor page content in template, but it doesn’t get styles and some widgets are missing
  39. Using WordPress templating for HTML emails
  40. Loading partial templates with AJAX/PJAX
  41. WP frontend output of custom textarea fields not respecting line breaks. In admin it’s OK
  42. How do you check if a WordPress template file exist?
  43. Load entire NextGEN gallery from single thumbnail?
  44. I put my blog on a subpage, how do I get page title?
  45. A special single page templates for posts under a category and all its child category
  46. Custom reset password template after forgot password request
  47. Outputting Canonical Resource URLs Across a Multisite Network?
  48. Gravity Forms Custom Templates [closed]
  49. Child Theme: how to override variables?
  50. How do I get the URL of a specific size featured image?
  51. Where to store some per-template preferences?
  52. add/apend templates ‘transparently’ via plugin to currently active theme or child theme?
  53. stop blog page from using index.php?
  54. How can I modify the default reset (lost) password email text?
  55. How to create tag.php
  56. Template files missing after moving site
  57. How do I override template-tags.php in twentyseventeen theme
  58. Get template part vs locate template function
  59. Programmatically change post templates?
  60. How to hide/redirect the author page
  61. Tools for Converting an Existing Website Design to a WordPress Template?
  62. Gutenberg & Pre-formatted Templates: Core Block Attributes
  63. Restrict a search to a custom post type
  64. passing argument to get_template_part() or a better way to code
  65. Gutenberg Editor – Template Doesn’t Match Error
  66. author.php added to template not working on Nginx server
  67. Test if page is child and has children, if so echo child pages also on grandchild pages
  68. Need to give custom page template for each language in WPML
  69. roots child theme can’t override header.php
  70. How did you incorporate WooCommerce in your own WordPress theme?
  71. Correct process for a new Page Template?
  72. Templates & CSS – Proper Programming Practice?
  73. How to assign a class to a page with a custom template?
  74. wordpress – load a template based on the URI
  75. When calling wp_title(), do you have to create some kind of “title.php” file?
  76. A shared custom taxonomy between two custom post types
  77. Creating a custom category page with pagination
  78. Create Page that uses specific template
  79. TwentyTen: Overloading template.php files vs. get_template_part
  80. Post formats template
  81. Sharing templates with the JSON API?
  82. New Template — copy existing template and change code? [duplicate]
  83. index.php template is used instead of blog page
  84. Using Includes in Templates in Document Head
  85. Proper Javascript Implementation
  86. How to show scaled featured image in template?
  87. Stream Video Player does not work with do_shortcode()?
  88. Same template for all the terms of a taxonomy
  89. Guest author’s post not display in author template
  90. Modifying searchform.php and search.php to have two kinds of searches
  91. Prevent private post 404
  92. Grid layout “last” class to every third item
  93. Where is the /blog/ url set from?
  94. Create a WordPress template without navigation and footer
  95. Load template inside a parent template
  96. Template redirect is_tax() not working
  97. Change site template from php
  98. Proper way to use get_the_content() in front-page.php and the content-home.php?
  99. How do you modify Page Template?
  100. Using “setup_postdata” with “get_template_part” does not work
Categories templates Tags post-meta, templates
WordPress Admin Tables in Post View
Any way to insert text on page from a query results?

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