Wordpress - Weird post template issue - wordpress

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.

Related

I want to add word "movie" before posts name in all url in wordpress

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".

rename cpt in wordpress

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.

Wordpress: How can I add to a custom post type child page its parent as slug?

When setting 'hierarchical' => true to a custom post type and assigning a parent to a page with this custom post type throws 404. It is posible to make this work?
Expected result: http://example.com/parent-page/page-title/
This works with Wordpress normal pages, but not with custom post types (404 not found).
Thanks in advance!
Since I just noticed you wanted a permalink structure exactly like pages, you can modify the rewrite parameter when you register your post type. Here is an example on how to make it just like pages structure:
$args = array(
'labels' => $labels,
'hierarchical' => true, // just to get parent child relationships with your custom post [but you already knew this part]
'description' => 'Your custom post type description here',
'has_archive' => false,
'rewrite' => array('slug' => '/'), // we rewrite the slug to the root url so that it has no post type prefix
'with_front' => false, // This is optional but just in case your posts are set to /blog/post-name this will make it /post-name for your custom post type
'capability_type' => 'post',
'supports' => array(
'title', 'editor', 'author', 'thumbnail', 'page-attributes'
)
);
register_post_type( 'post_type', $args );
Also make sure you update the permalink structure after you make these changes so Wordpress can rewrite the rules.

Custom Post Type - Append post slug to current URL

I've registered a custom post type portfolio.
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __('Portfolio', THEMENAME),
'singular_name' => __('Portfolio', THEMENAME),
),
'public' => true,
'supports' => array('title','editor','thumbnail'),
)
);
I also have a Page Template that list all the portfolio items with title My Works. The URL of the page that uses the template is:
http://sitename/my-works
However when I create a portfolio post I get a URL like this:
http://sitename/portfolio/post-name
Is it possible when an item in the Page Template is clicked for it to redirect to:
http://sitename/my-works/post-name
I have a feeling that this have something to do with the rewrite argument?
Set the permalinks to /%postname%/
You need to set the rewrite like this:
'rewrite' => array(
'slug' => ''
),

Change custom post type url

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);

Resources