I want to add '/blog' in front of my all blog posts. I changed this from 'Setting -> Permalinks -> Custom Structure' but it adds '/blog' to all custom posts as well. I am using lots of custom posts and custom categories.
I found some solutions here. In this solution all working fine but there is no solution to remove '/blog' from custom category url.
I got the solution. Just add 'rewrite' => array( 'with_front' => false ), this into custom category arguments array.
IMPORTANT: Do not forget to flush and regenerate the rewrite rules database after modifying rules. From WordPress Administration Screens, Select Settings -> Permalinks and just click Save Changes without any changes.
See below Eg.
$args = array(
'labels' => $labels,
'rewrite' => array( 'with_front' => false ),
'hierarchical' => true,
);
register_taxonomy( $taxonomy, $object_type, $args );
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".
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.
I am quit new to wordpress and have a problem I cannot seems to solve even with a day of google searching. This is what I did:
I have created a custom post type called lookbook. This works fine and I can add new items and such.
I added a taxonomy so I could add an category to it.
function lookbook_taxonomy() {
register_taxonomy( 'jeans','lookbook',
array(
'hierarchical' => true,
'label' => 'jeans',
'query_var' => true,
'rewrite' => true
)
);
}
Using wp_query or query_posts I can retrieve the lookbook items and display their content.
(problem) When I pres the category link provided by word press the page just goes back to index. The link changes to the desired filter however NO post are being filtered. I tried all kinds of stuff but I can seems to find a way to just press the category link and just diplay those post.
update: (code I used to register post type)
add_action('init', 'lookbook_register_post_type');
function lookbook_register_post_type() {
register_post_type('lookbook', array(
'labels' => array(
'name' => __('lookbook'),
'singular_name' => __('lookbook')),
'public' => true,
'capability_type' => 'post',
'supports' => array(
'title',
'excerpt'
),
'has_archive' => true,
'taxonomies' => array('category','post_tag')
)
);
}
You'll need to add 'has_archive' => true to your register_post_type arguments array if it's not already there.
Additionally, make sure you have the necessary template files ready. Read up on Wordpress' Template Hierarchy.
If you show us the code you used to register the post type, as well as what code makes up "the category link", we might be of more help!
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.
I have created a custom post type as seen below,
function transactions_register() {
$args = array(
'label' => __('Transactions'),
'singular_label' => __('Transaction'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array("slug" => "transaction"),
'supports' => array('title', 'editor', 'thumbnail')
);
register_post_type( 'transaction' , $args );
}
I have set my permalinks to be like this /%category/%postname however when I navigate to a transaction, the URL looks like this,
http://www.domian.com/transaction/test
However this returns the following server error
The page cannot be found
How can I make it so my custom post type will work with my permalink setting?
Whenever you add custom post type, just go to Settings -> Permalinks and click on "Save" or was it "Update". It does the magic.
Every time you create custom post type or custom taxonomy you have to goto Settings -> Permalinks and hit save. its wordpress known bug.