Custom post types, taxonomies, and permalinks

Change slug in your post type arguments to products/%product_cat%, and slug in your taxonomy arguments to just products, then flush your rewrite rules. WordPress should now handle /products/my-product-cat/post-name/! Now finally, we need to help WordPress a little with generating permalinks (out of the box, it won’t recognise the permastruct tag %product_cat%): /** * Inject term … Read more

How to disable the single view for a custom post type?

METHOD 1: Redirect to a custom URL for single view, archive page is still publicly accessible. You can use template_redirect hook to redirect for a custom post type, you can use any other URL you want to in place of home_url() and the error code in other argument. <?php add_action( ‘template_redirect’, ‘wpse_128636_redirect_post’ ); function wpse_128636_redirect_post() … Read more

Custom Post Type Templates from Plugin Folder?

You can use single_template filter hook. /* Filter the single_template with our custom function*/ add_filter(‘single_template’, ‘my_custom_template’); function my_custom_template($single) { global $post; /* Checks for single template by post type */ if ( $post->post_type == ‘POST TYPE NAME’ ) { if ( file_exists( PLUGIN_PATH . ‘/Custom_File.php’ ) ) { return PLUGIN_PATH . ‘/Custom_File.php’; } } return … Read more

What does this PHP function code mean? [closed]

Basically, this is a programming pattern for namespacing code within a WordPress plugin. Typically, you can only have one function called init() in a program, but more than one author will try to use that name. Placing function names in a class is a way around this limitation. For example: class Towfiq_Person { static function … Read more

Where to put my code: plugin or functions.php?

I would start with this question: Is the functionality related to presentation of content, or with generation/management of content, or of the site, or of the user identity? If the functionality is not related specifically to presentation of content, then it is squarely within Plugin Territory. This list is long: Modifying core WP filters (wp_head … Read more

Adding a Taxonomy Filter to Admin List for a Custom Post Type?

UPDATE: I’ve included a new complete answer but even so I’ve left my original response at the bottom to which the first few comments reference. Hi @tarasm: Although I said it shouldn’t be hard it is a little involved. But before we dig into the code… The Screenshots: …let’s check out some screen shots for … Read more