How do you use a CPT as the default home page?

Thanks to @toscho for the useful answer, but it felt a bit hackish to me, so I poked around a bit and figured out I could add a filter instead: function wpa18013_add_pages_to_dropdown( $pages, $r ){ if(‘page_on_front’ == $r[‘name’]){ $args = array( ‘post_type’ => ‘stack’ ); $stacks = get_posts($args); $pages = array_merge($pages, $stacks); } return $pages; … Read more

Display all posts in a custom post type, grouped by a custom taxonomy

So, you might consider automating the multiple queries. First, get the list of terms in your custom taxonomy, using get_terms(): <?php $member_group_terms = get_terms( ‘member_group’ ); ?> Then, loop through each one, running a new query each time: <?php foreach ( $member_group_terms as $member_group_term ) { $member_group_query = new WP_Query( array( ‘post_type’ => ‘member’, ‘tax_query’ … Read more

Load a script just to custom post type in admin

Try this code for adding scripts to the edit pages of your portfolio custom post type. add_action( ‘admin_print_scripts-post-new.php’, ‘portfolio_admin_script’, 11 ); add_action( ‘admin_print_scripts-post.php’, ‘portfolio_admin_script’, 11 ); function portfolio_admin_script() { global $post_type; if( ‘portfolio’ == $post_type ) wp_enqueue_script( ‘portfolio-admin-script’, get_stylesheet_directory_uri() . ‘/admin.js’ ); }

Adding categories to custom post type in permalink

There are 2 points of attack to cover when you are adding custom post type rewrite rules: Rewrite rules This happens when the rewrite rules are being generated in wp-includes/rewrite.php in WP_Rewrite::rewrite_rules(). WordPress allows you to filter the rewrite rules for specific elements like posts, pages and various types of archive. Where you see posttype_rewrite_rules … Read more

Remove taxonomy slug from a custom hierarchical taxonomy permalink

UPDATE Since writing this WordPress core has added the ‘do_parse_request’ hook that allows URL routing to be handled elegantly and without the need to extend the WP class. I covered the topic in-depth in my 2014 Atlanta WordCamp talk entitled “Hardcore URL Routing“; the slides are available at the link. ORIGINAL ANSWER URL Design has … Read more

WP REST API fetch posts from post type

Just add the next parmater into the function register_post_type, it can be before ‘menu_position’parameter. ‘show_in_rest’ => true if you’re using a plugin to register your posttype you can use the next code: add_action( ‘init’, ‘add_anuncios_to_json_api’, 30 ); function add_anuncios_to_json_api(){ global $wp_post_types; $wp_post_types[‘anuncio’]->show_in_rest = true; } after that, you’ll be able to list your posts from … Read more

Change the text on the Publish button

If you look into /wp-admin/edit-form-advanced.php, you will find the meta box: add_meta_box(‘submitdiv’, __(‘Publish’), ‘post_submit_meta_box’, $post_type, ‘side’, ‘core’); Note the __(‘Publish’) – the function __() leads to translate() where you get the filter ‘gettext’. There are two ways to handle your problem: 1. Address the string in a single specialized function (be sure to match the … Read more

Hide content box with Custom Post Type?

Yes, remove the editor support from your custom post type. You can do it in two ways. While registering your custom post type: Example: $args = array( ‘public’ => true, ‘publicly_queryable’ => true, ‘show_ui’ => true, ‘show_in_menu’ => true, ‘capability_type’ => ‘post’, ‘has_archive’ => true, ‘supports’ => array(‘title’,’author’,’thumbnail’,’excerpt’,’comments’) ); register_post_type(‘book’,$args); 2.Using the remove_post_type support if … Read more

Change “Enter Title Here” help text on a custom post type

There is no way to customize that string explicitly. But it is passed through translation function and so is easy to filter. Try something like this (don’t forget to change to your post type): add_filter(‘gettext’,’custom_enter_title’); function custom_enter_title( $input ) { global $post_type; if( is_admin() && ‘Enter title here’ == $input && ‘your_post_type’ == $post_type ) … Read more

Custom post type single page returns 404 error

You should set your publicly_queryable argument to true when registering your custom post type. TAKE NOTE: Add flush_rewrite_rules(), refresh the page once or twice and REMOVE IT IMMEDIATELY. You SHOULD NOT keep flush_rewrite_rules() unless under the provisions as in the codex. this is an expensive operation so it should only be used when absolutely necessary

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