Dynamically Create Custom Post Type According to Relationship Another Custom Post Type

I would have the goal of appending the other device onto any existing permalink so you can compare one to the other, and vice versa. That’s fully dynamic/automatic; i.e., requires no manual entry and no CRON job, etc. So let’s pretend you have: https://example.com/mobile-device-a/ We want to add support for: https://example.com/mobile-device-a/compare/mobile-device-b/ https://example.com/mobile-device-b/compare/mobile-device-a/ See: add_rewrite_endpoint() Create … Read more

Custom Post Type | Fatal Error on register_post_type()

try these changes: 1) To use add_action() when your plugin or theme is built using classes instead of passing just the function name, you need to pass an array with a reference to the class ($this) and the callable function (‘custom_post_type’) function __construct() { add_action(‘init’, array( $this, ‘custom_post_type’ ) ); } 2) The original ‘activate’ … Read more

how to rewrite args in a custom post type from your functions.php?

The $rewrite parameter of register_post_type() accepts either a boolean or an array. We can overwrite the existing value of $rewrite with the array of our desired settings: function overwrite_gallery_slug( $args, $post_type ) { if ( $post_type === ‘gallery’) { $args[‘rewrite’] = array ( ‘slug’ => ‘team-murray’, ‘with_front’ => false, ); } return $args; } add_filter( … Read more

Problem adding column to WC Subscription [closed]

Alright, so since WC Subscriptions is creating it’s own array for columns. Any filter priority lesser than their function will simply make your code non-functional. So what I did is I changed priority from 10 to 1000 so that my codes fire after their code. add_filter( ‘manage_shop_subscription_posts_columns’, function ($columns) { $columns[‘my_field’] = __(‘My Field’); return … Read more

Classic editor showing in Gutenberg when creating a custom post type

Yep, you just need to add ‘show_in_rest’ => true Here’s the full snippet: // Register Custom Post Type function custom_post_type() { $labels = array( ‘name’ => _x( ‘Post Types’, ‘Post Type General Name’, ‘text_domain’ ), ‘singular_name’ => _x( ‘Post Type’, ‘Post Type Singular Name’, ‘text_domain’ ), ‘menu_name’ => __( ‘Post Types’, ‘text_domain’ ), ‘name_admin_bar’ => … Read more

Merge multiple custom post types in a single archive template

As Jacob Peattle mentioned, you should not be using query_posts in your custom archive templates, that’s redundant as WP is already going to query those posts for you. What you really need is pre_get_posts (https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts). That will allow you to conditionally modify the parameters of the main query before it executes. Additionally since you are … Read more

Custom post type – how can I make it a sub-url of another page?

When you register the CPT, use the rewrite argument to add the prefix. For example if your CPT is currently registered like this: <?php function wpse_create_cpt_testimonial() { $args = array( ‘public’ => true, ‘label’ => __( ‘Testimonials’, ‘textdomain’ ), // … you probably have other arguments as well ); register_post_type( ‘testimonial’, $args ); } add_action( … Read more