how to properly include or get file contents in a wordpress theme

There are 2 problems: include( get_template_directory() . ‘/audiounity/result.php’ ); The result of this is likely: /srv/www/example.com/public_html/wp-content/themes/audiounity/audiounity/result.php The first line of the Codex entry for that function is: Retrieves the absolute path to the directory of the current theme. If it’s a child theme, then you need to use get_stylesheet_directory. *_template_* functions always refer to the … Read more

Custom Post Type setup

You can set any arbitrary path in the rewrite slug and has_archive arguments: $args = array( ‘rewrite’ => array(‘slug’ => ‘people/researchers’), ‘has_archive’ => ‘people/researchers’, // other args… ); EDIT Your post type slug is researchers, so WordPress will be looking for the file archive-researchers.php by default. If you want to force a different template, you … Read more

How to use a template file to show all post having same metakey

You might give it a shot this way: add_filter( ‘template_include’, ‘check_post_meta_template_include’ ); function check_post_meta_template_include( $template ) { if ( !is_single() ) { return $template; } global $post; if ( $post->post_type != ‘post’ ) { // Proceed only if post type = post return $template; } $category_meta = get_post_meta( $post->ID, ‘Category’, true ); if ( $category_meta … Read more

Can I assign a Folder for Post Formats, without it affecting WordPress’ fallback/hierarchical system?

In general, “bad practice” is so common in the wordpress ecosystem, you will have to do something really bad for anyone to actually signal you out for doing it 😉 If you are the developer and maintainer of the theme, you should develop it in a way which will be easy for you to maintain … Read more

Index template always follows page_template() template?

template_include is a filter hook so you should use add_filter() instead of add_action(), it’s breaking the semantics here. Though both functions internally do the same thing. Try the following code, I haven’t tested it but it should work. Simplified and removed some codes. add_filter(‘template_include’, [$self, ‘load_route_template’]); public function load_route_template($template) { if (!$this->matched_route instanceof Route || … Read more

Editing a post template

can you try changing these lines: ‘order_by’ => ‘custom’, ‘meta_key’ => ‘Last Name’, in each of the above sections with this code: ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘last_name_sort’ => array( ‘key’ => ‘last_name’, ‘compare’ => ‘EXISTS’, ), ‘first_name_sort’ => array( ‘key’ => ‘first_name’, ‘compare’ => ‘EXISTS’, ), ), ‘orderby’ => array( ‘last_name_sort’ => ‘ASC’, … Read more

Custom template for sub-sub-categories

Instead of include(), use get_template_part() https://developer.wordpress.org/reference/functions/get_template_part/ <?php $post = $wp_query->post; if (cat_is_ancestor_of( 42, $cat ) ) { get_template_part( ‘services’, ‘template’ ) } else { get_template_part( ‘single’, ‘default’ ); } ?> If you create those files and use get_template_part(), then within those files you can set them up to display posts however you see fit. Take … Read more