Hello i have one cpt which is case studies but i want to rename it as portfolio .and i have created 10 post under case studies cpt .. so can i rename it cpt ? actually i want change in url .. currently my url is http://www.praxinfo.com/case-studies-page/whatscrackin/ but i want http://www.praxinfo.com/portfolio/whatscrackin/. so how to do this in wordpress?
In your register_post_type use the rewrite option to change the url but not the actual name of the cpt. This way, you won't run into database problems and your users will still see the new name.
Example from the WordPress codex:
add_action( 'init', 'create_posttype' );
function create_posttype() {
register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'products'),
)
);
}
Here, the url would be /products/ even though the name of the cpt is acme_product.
Related
http://127.0.0.1/wordpress/{{movie}}/watch-appetite-for-love-2016-free-on-123movieshub/
I want all my url to show movie word before postname
By setting this custom permalink value /movie/%postname%/ as Custom Structure at /wp-admin/options-permalink.php page.
It sounds like you would benefit from using a custom post type. These take on the URL of their name by default if you have pretty urls. You can also force the slug you want. This is a basic post type there are a lot more options on the Wordpress Developer Codex.
function create_movie_post_type() {
register_post_type( 'movies',
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'movie'),
)
);
}
add_action( 'init', 'create_movie_post_type' );
This gives you a lot more control over that particular post type and keeps it separate from the native "post".
I've a custom post type by name 'Portfolio'. It's generating the url as /portfolio/xxx when I make any post. I want to change it to 'Products'.
Change custom post-type rewrite
I've tried this but it doesn't suppose to work.
I am presuming you have added the custom post type yourself, in which case it is easy.
When you register a new post type, you can set any rewrite rules for that post type to follow as part of the arguments used in the register_post_type( 'name', $args ) function.
If your post type is available on the front end and is public, then by default WordPress will use the custom post name as the slug. You can override this as follows:
$args = array(
// your other arguments
'rewrite' => array(
'slug' => 'products', // use this slug instead of post type name
'with_front' => FALSE // if you have a permalink base such as /blog/ then setting this to false ensures your custom post type permalink structure will be /products/ instead of /blog/products/
),
);
register_post_type( 'portfolio', $args );
The other arguments you can use are documented at http://codex.wordpress.org/Function_Reference/register_post_type
Please see the documentation on URLs of Namespaced Custom Post Types Identifiers. One of the options available to you is to add a 'rewrite' argument to register_post_type(). From the docs:
When you namespace a custom post type identifier and still want to use a clean URL structure, you need to set the rewrite argument of the register_post_type() function. For example:
add_action( 'init', 'create_posttype' );
function create_posttype() {
register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Portfolio' ),
'singular_name' => __( 'Portfolio' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'products'),
)
);
}
You'll then likely need to login to the admin and re-save your permalinks.
Use the rewrite property
$args= array(
// other settings
'rewrite' => array( 'slug' => 'Products' ),
);
register_post_type( 'portfolio', $args);
I am working on a wordpress website. I need to add custom Post types. I have created a custom post type products which has a taxonomy product_type which is similar to category . There are various taxonomy value for product_type . Some of them are flowers, extracts etc .
Now I am trying to visit this link http://farma.mechadigital.net/products/product_type/flowers/ and it doesnt work for me.
I have added some files.
archive-products => This should be the custom post template
taxonomy-product_type.php => This should be the taxonomy Template
taxonomy-product_type-flowers.php => This should be the template for the term value flowers
Here is the code that I have included in functions.php. I dont know where I am doing it wrong.
functions.php
function farma_products() {
$labels = array(
// List of arguments
);
$args = array(
// list of arguments
'rewrite' => array( 'slug' => 'products' ),
);
register_post_type( 'products', $args );
flush_rewrite_rules(false);
}
add_action( 'init', 'farma_products_type' );
function farma_products_type() {
register_taxonomy(
'product_type',
'products',
array(
'label' => __( 'Product Type' ),
'rewrite' => array( 'slug' => 'products/product_type' ),
'hierarchical' => true,
)
);
}
I have a clean WordPress installation using Twenty Eleven, with no plugins or other modifications. The blog contains approximately 800 posts with related tags and categories.
I'd like to move all these posts to a custom post type. By adding the following code to my functions.php my blog now has the custom post type installed and working perfectly.
//Add custom post type
add_action( 'init', 'create_en_post_type' );
function create_en_post_type() {
register_post_type( 'en_post', array(
'labels' => array(
'name' => __( 'English Posts' ),
'singular_name' => __( 'English Post' )
),
'public' => true,
'menu_position' => 5,
'rewrite' => array('slug' => 'en'),
'supports' => array(
'title',
'editor',
'author',
'excerpt',
'comments',
'custom-fields'
)
));
}
//Add belonging custom taxonomy
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy( 'english_categories', 'en_post', array( 'hierarchical' => true, 'label' => 'English Categories', 'query_var' => true, 'rewrite' => true ) );
register_taxonomy( 'english_tags', 'en_post', array( 'hierarchical' => false, 'label' => 'English Tags', 'query_var' => true, 'rewrite' => true ) );
}
Now all I need is to change the regular post type to my custom post type. I've managed to move the posts using the plugin Convert Post Types, but my taxonomies aren't converted.
I realize I could just create similar custom categories and assign the custom posts to them, but what about tags? How can I convert these (automatically, 1200 tags)?
I've tried manually messing around in the database, but I can't make it work.
You should change the ID's in the database, take a long look at the phpmyadmin
wp_term_taxonomy
wp_terms
wp_term_relationships
In the terms table you will find the id of the old and new taxamonies
in term_taxonomy replace all old term_id with the new.
SQL:
UPDATE `wp_term_relationships` SET `term_id` = REPLACE(`term_id`, /*old id*/, /*new id*/);
Do make a backup before you start
Im using the example from the wordpress site to add new post type, im using wp3.2.1, which is as below
// Add custom post type for the case studies
add_action( 'init', 'create_casestudy_post_type' );
function create_casestudy_post_type() {
register_post_type( 'case_study',
array(
'labels' => array(
'name' => __( 'Case Studies' ),
'singular_name' => __( 'Case Studies' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'case-studies')
)
);
}
This code i have put in the functions.php file in my themes directory.
The problem is when i try and view the URL, it returns a 404 page not found ... im using single-case_study.php for the page template, but it just 404's all the time.
My permalinks are set to /%category%/%postname%/ in the custom structure.
Any help? .. this is really bugging me out
Cheers
You can use Custom Post Type UI plugin to create a custom post type.