How do I create a relationship between two custom post types?

Using a Plugin Some very good plugins for relationships: ACF Relationship Field Posts-2-Posts Using a Metabox You can build a simple relationship using metaboxes: add_action( ‘admin_init’, ‘add_meta_boxes’ ); function add_meta_boxes() { add_meta_box( ‘some_metabox’, ‘Movies Relationship’, ‘movies_field’, ‘series’ ); } function movies_field() { global $post; $selected_movies = get_post_meta( $post->ID, ‘_movies’, true ); $all_movies = get_posts( array( … Read more

How to use a custom post type archive as front page?

After you have set a static page as your home page you can add this to your functions.php and you are good to go. This will call the archive-POSTTYPE.php template correctly as well. add_action(“pre_get_posts”, “custom_front_page”); function custom_front_page($wp_query){ //Ensure this filter isn’t applied to the admin area if(is_admin()) { return; } if($wp_query->get(‘page_id’) == get_option(‘page_on_front’)): $wp_query->set(‘post_type’, ‘CUSTOM … Read more

Add Custom Fields to Custom Post Type RSS

function add_custom_fields_to_rss() { if(get_post_type() == ‘my_custom_post_type’ && $my_meta_value = get_post_meta(get_the_ID(), ‘my_meta_key’, true)) { ?> <my_meta_value><?php echo $my_meta_value ?></my_meta_value> <?php } } add_action(‘rss2_item’, ‘add_custom_fields_to_rss’); You should be able to substitute and any other meta values you need to add to the feed.

Get terms by taxonomy AND post_type

Here is another way to do something similar, with one SQL query: static public function get_terms_by_post_type( $taxonomies, $post_types ) { global $wpdb; $query = $wpdb->prepare( “SELECT t.*, COUNT(*) from $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN $wpdb->term_relationships AS r ON r.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN $wpdb->posts AS p … Read more

Row actions for custom post types?

When using custom post type you use the post_row_actions filter hook and check the post type to modify it only: add_filter(‘post_row_actions’,’my_action_row’, 10, 2); function my_action_row($actions, $post){ //check for your post type if ($post->post_type ==”feedbacks”){ /*do you stuff here you can unset to remove actions and to add actions ex: $actions[‘in_google’] = ‘<a href=”http://www.google.com/?q=’.get_permalink($post->ID).'”>check if indexed</a>’; … Read more

Custom post type – order field

When declaring your custom post type using the register_post_type function, you have to add ‘page-attributes’ to the support field, like in the following example: register_post_type(‘myposttype’, array( ‘supports’ => array(‘title’, ‘editor’, ‘page-attributes’), ‘hierarchical’ => false )); You’ll need to add any other supported meta boxes as well to the ‘supports’ field, see https://developer.wordpress.org/reference/functions/register_post_type/ for more information … Read more