How to set default status to custom post type

Hook wp_insert_post_data filter to force a post status to be set as incomplete before it can be set as published. With the following code only a post that is set as incomplete can be saved: add_filter( ‘wp_insert_post_data’, ‘prevent_post_change’, 20, 2 ); function prevent_post_change( $data, $postarr ) { if ( ! isset($postarr[‘ID’]) || ! $postarr[‘ID’] ) … Read more

get_the_post_thumbnail() returning empty string on custom post type

If nothing works, give this a try: $img_attribs = wp_get_attachment_image_src( get_post_thumbnail_id(), ‘thumbnail’ ); // returns an array if( $img_attribs ) { ?> <img src=”https://wordpress.stackexchange.com/questions/115607/<?php echo $img_attribs[0]; ?>” width=”<?php echo $img_attribs[1]; ?>” height=”<?php echo $img_attribs[2]; ?>”> <?php } ?>

Jetpack infinite scroll render – make different depending on post type?

Replace the above mytheme_render_infinite_scroll function with this: function mytheme_render_infinite_scroll() { while ( have_posts() ) : the_post(); if (‘mytheme_portfolio’ == get_post_type()) : get_template_part( ‘content’, ‘archive-portfolio’ ); else : get_template_part( ‘content’, get_post_format() ); endif; endwhile; }

How to create archive page for taxonomy terms within custom post type

There is an example in the WP Codex which should work for you: Try the following naming convention for your taxonomy term archive template: taxonomy-{taxonomy}-{term}.php So, let’s say you have a CPT named “Projects,” a taxonomy named “Maintenance,” and a term within the taxonomy named “Professional.” Then your naming convention would be: taxonomy-maintenance-professional.php

Actions that Run on Admin Edit Page Load After Posts Are Queried

What actions run on the edit page in the admin section of a post type Here are the do_action and do_action_ref_array calls, for the edit.php (post) screen, without any plugins and with a default theme activated: muplugins_loaded – do_action registered_taxonomy – do_action registered_taxonomy – do_action registered_taxonomy – do_action registered_taxonomy – do_action registered_taxonomy – do_action registered_post_type … Read more

How to register custom post types in a plugin?

The init hook is the first hook allowed. If called earlier it won’t work. See WP Codex: https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/ Create or modify a post type. register_post_type should only be invoked through the ‘init’ action. It will not work if called before ‘init’, and aspects of the newly created or modified post type will work incorrectly if … Read more