Page Templates – this code only works for one Custom Post Type

Dump the constant MY_CUSTOM_POST_TYPE use the $post->post_type instead. /** * Register the meta box */ add_action(‘add_meta_boxes’, ‘page_templates_dropdown_metabox’); function page_templates_dropdown_metabox(){ global $post; add_meta_box( $post->post_type.’-page-template’, __(‘Template’, ‘my_template’), ‘render_page_template_dropdown_metabox’, $post->post_type, ‘side’, #I prefer placement under the post actions meta box ‘low’ ); } /** * Render your metabox – This code is similar to what is rendered on … Read more

Custom post type tag archives don’t work for basic loop?

Down the rabbit hole….. I found a fix. From this post Custom Post Type Archives by Date and Taxonomy Which let me to this trac ticket http://core.trac.wordpress.org/ticket/14589 and the following function post_type_tags_fix($request) { if ( isset($request[‘tag’]) && !isset($request[‘post_type’]) ) $request[‘post_type’] = ‘any’; return $request; } add_filter(‘request’, ‘post_type_tags_fix’); Maybe this didn’t make it into 3.1?

How I upload, save and set a featured image from my frontend?

sorry this isn’t an answer but you need to sanitize that user input. Your allowing tags to be written directly into your post content which allows anyone to run javascript in both wp admin and on the front end of your site (assuming you’ll eventually print these posts). highly recommend (at minimum) strip_tags() or htmlspecialchars() … Read more

Remove Custom Post Type menu for non-administrator users.

Codex – Register Post Type See the capability_type and capabilities arguments for register_post_type. You can pass the capabilities argument an array of capabilities to map to the necessary caps, here’s an example of the args array with custom capabilities. $args = array( ‘labels’ => $labels, ‘public’ => true, ‘publicly_queryable’ => true, ‘show_ui’ => true, ‘query_var’ … Read more

Get the Category Name instead of ID from WP-API

This code will add categories_names field to wp rest api response: function wpse_287931_register_categories_names_field() { register_rest_field( ‘project’, ‘categories_names’, array( ‘get_callback’ => ‘wpse_287931_get_categories_names’, ‘update_callback’ => null, ‘schema’ => null, ) ); } add_action( ‘rest_api_init’, ‘wpse_287931_register_categories_names_field’ ); function wpse_287931_get_categories_names( $object, $field_name, $request ) { $formatted_categories = array(); $categories = get_the_category( $object[‘id’] ); foreach ($categories as $category) { $formatted_categories[] … Read more

How to create user personal pages with information from their meta profile fields?

First of all register the cpt. Probably if you don’t want add the UI for that post type you can set the show_ui to false. $args = array( ‘label’ => ‘Members’, ‘public’ => true, ‘exclude_from_search’ => true, ‘show_ui’ => false, ‘show_in_nav_menus’ => false, ‘show_in_menu’ => false, ‘show_in_admin_bar’ => false, ‘hierarchical’ => false, ‘has_archive’ => true, … Read more