How do I add html content to custom post type Posts using php?

After searching through the wordpress docs, I found what I needed. What I was missing was the hook called “the_content”. My function, and all the code I wrote inside it, was correct. I just needed this stupid hook. function displayIframe($content) { //[my code to get the $currentPostID and $currentPostGuid] //… //… if (is_single( $currentPostID )) … Read more

How do I assign a block template (.html) to a custom post type?

Classic and block(-based) themes both use the same template hierarchy, so for example in classic themes, we can add a template named single-<post type>.php which would be used as the default template for displaying single posts in a specific post type, and in block themes, the equivalent template is named single-<post type>.html, but that template … Read more

Get a list of all custom post type names/slugs [duplicate]

OK, so the function get_post_types is exactly what you’re looking for. $args = array( ‘public’ => true, ‘_builtin’ => false ); $output=”names”; // names or objects, note names is the default $operator=”and”; // ‘and’ or ‘or’ $post_types = get_post_types( $args, $output, $operator ); foreach ( $post_types as $post_type ) { echo ‘<p>’ . $post_type . … Read more

How do I find a way to create a global single.php for a custom post type?

There re various filters you can use to inject your custom template. One being the template_include, the other single_template, and even type_template. The easiest one would be single_template in your case (example from codex): function get_custom_post_type_template($single_template) { global $post; if ($post->post_type == ‘my_post_type’) { $single_template = dirname( __FILE__ ) . ‘/post-type-template.php’; } return $single_template; } … Read more

Custom Post Type Advanced Slug

This is pretty straightforward using a rewrite endpoint. The first step is to set an ep_mask when you register your taxonomy, which is part of the rewrite argument. Note that it’s a constant, and should be as-is, without quotes: $args = array( ‘rewrite’ => array( ‘slug’ => ‘location’, ‘with_front’ => false, ‘ep_mask’ => EP_TAGS ), … Read more