get_page_by_title() doesn’t retrieve my post

The second parameter for get_page_by_title() is $output, with the third being $post_type. This should solve your porblem – $patchwork = get_page_by_title( ‘Patchwork 01’, OBJECT, ‘patchwork’ ); echo $patchwork->ID; Please have a look at the Function Reference for get_page_by_title() for more information.

Featured Image field not appearing in Custom post type

use this code to create a custom post type, mainly you need to include this line: ‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’, ‘thumbnail’, ), ” full code to create: // Register Custom Post Type function custom_post_type() { $labels = array( ‘name’ => _x( ‘Post Types’, ‘Post Type General Name’, ‘text_domain’ ), ‘singular_name’ => _x( ‘Post … Read more

Get term name without a foreach loop

What about using: echo get_the_term_list( $post->ID, ‘artist-genre’, ‘<li>’, ‘,</li><li>’, ‘</li>’ ); instead, to generate the HTML list? Or simply: the_terms( $post->ID, ‘artist-genre’, ‘<li>’, ‘,</li><li>’, ‘</li>’ ); that’s a wrapper for get_the_term_list(). Also notice that you’re missing the is_wp_error() check, in your code snippet, because wp_get_post_terms() can return the WP_Error object, for an unknown taxonomy. But … Read more

how to echo meta tag in header using php

Use the_title_attribute() to print the attribute. A post title might contain HTML, so you need the escaped content that this function returns. Also suppress immediate print-out, because that will set the output in front of the echo statement. if ( is_singular( ‘communications’ ) ) { $title = the_title_attribute( [ ‘echo’ => FALSE ] ); echo … Read more

How to create subcategory for Custom Post Type?

WordPress doesn’t support nested post types, though you can created hierarchical types similar to the Core “Page” type. However, what you are describing, including this sample “POST+CATEGORY+SUBCATEOGRY” is a custom taxonomy for your Car post type. The Codex has examples, but you would need something like this (roughly, I am sure this needs tweaked): add_action( … Read more

Pagination broken by naming conflict between CPT and Page

You can add a rewrite rule to override the post type rules and force it to load your page. function wpd_fix_insights_pagination(){ add_rewrite_rule( ‘insights/page/([0-9]+)/?$’, ‘index.php?pagename=insights&paged=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘wpd_fix_insights_pagination’ ); Visit your Settings > Permalinks admin page after adding this code to flush rewrite rules.