Restrict custom post type to only site administrator role

register_post_type() accepts a parameter capabilities in its arguments. See get_post_type_capabilities() for possible values. From the comments: By default, seven keys are accepted as part of the capabilities array: edit_post, read_post, and delete_post are meta capabilities, which are then generally mapped to corresponding primitive capabilities depending on the context, which would be the post being edited/read/deleted … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)