Custom Search Template for Custom Post Types

Try adding the return as well in the else{}, like this: function template_chooser($template) { global $wp_query; $post_type = get_query_var(‘post_type’); if( $wp_query->is_search && $post_type == ‘product’ ) { return locate_template(‘archive-products.php’); } else { $args = array_merge( $wp_query->query, array( ‘post_type’ => ‘post’ ) ); query_posts( $args ); return locate_template(‘archive-products.php’); } return $template; } add_filter(‘template_include’, ‘template_chooser’); Haven’t tested.

Create custom post type with parameters

if you are not taking care about backward compatibility (works only when run under PHP 5.3 and later), you can employ the anonymous function: add_action( ‘init’, function() { $pluralName=”PluralName”; $singularName=”SingularName”; custom_poster( $pluralName, $singularName ); } ); Or closure $singularName=”Singular Name”; $pluralName=”Plural Name”; add_action( ‘init’, function() use ($singularName, $pluralName) { custom_poster( $pluralName, $singularName ); } );

Why is a custom post type’s URL “/?cposts=name-of-the-post” but default post’s URL is “/?p=ID”?

For normal posts you can set the permalink structure on Settings → Permalinks. All details can be found in the Codex For custom post types you can set the slug when you registering it: add_action( ‘init’, ‘create_posttype’ ); function create_posttype() { register_post_type( ‘cpost’, array( ‘labels’ => array( ‘name’ => __( ‘cpost’ ), ‘singular_name’ => __( … Read more

predefined custom field on registration page

Find <div id=tab2_login” and replace it with following code.Assuming you will change CSS and JS accordingly. <div id=”tab2_login” class=”tab_content_login” style=”display:none;”> <h3>Register for this site!</h3> <p>Sign up now for the good stuff.</p> <form method=”post” action=”<?php echo site_url(‘wp-login.php?action=register’, ‘login_post’) ?>” class=”wp-user-form”> <div class=”username”> <label for=”user_login”><?php _e(‘Username’); ?>: </label> <input type=”text” name=”user_login” value=”<?php echo esc_attr(stripslashes($user_login)); ?>” size=”20″ id=”user_login” … Read more

Questions on WordPress Codex Concept

Adding here. register_post_type function have a parameter public which controls how the type is visible to authors and readers. If public parameter of a post type is true then post type will be exclude_from_search, publicly_queryable, show_in_nav_menus, and show_ui. Read more about it in register_post_type function. Also all post types must be registered to use in … Read more