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!
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 know there are number of posts already available here regarding this particular issue and I have gone through a number of them but could not make my page to work. So I want to put here what I exactly have and looking forward to a solution.
I have registered the following Custom Post Type.
$labels = array('name' => 'Hotel','singular_name' => 'Hotel','admin_menu' => 'Hotel', 'name_admin_bar' => 'Hotel');
$supports = array(
'title',
'editor',
'thumbnail'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'query_var' => true,
'has_archive' => true,
'capability_type' => 'post',
'taxonomies' => array ('hotel_type', 'room_type', 'amenities'),
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 28,
'hierarchical' => false,
'rewrite' => array('slug' => 'hotels'),
'supports' => $supports,
'exclude_from_search' => false
);
register_post_type('hotel-info', $args);
Created a template page called hotel-list.php
Created a page using the above template (List of Hotels) in admin called Staying Options and updated its permalink to /hotels/.
Re-saved permalink structure from Settings > Permalink
But whenever I am trying to access http://local.tourplanner.com/hotels/ WordPress is taking me back to my homepage.
Somebody please tell me what I am doing wrong.
EDIT:
When I am accessing http://local.tourplanner.com/hotels/cliff-top-club-auli/ I am able to land on the correct page with information about the hotel.
You have created a slug only for individual hotels, and not for all hotels. Wordpress simply doesn't know how to list your hotels.
In order to make /hotels/ accessible, you'll need to create an archive page, which will be used to list the hotels. First have a quick look at the Post Type Template documentation here: https://codex.wordpress.org/Post_Type_Templates. Then follow the guide on how to create the archive page here http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-post-types-archive-page-in-wordpress/
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've defined a custom post type in wordpress in this way:
add_action('init', 'register_cima_fellowship');
function register_cima_fellowship() {
$args = array(
'labels' => $labels,
'public' => true,
'menu_position'=>20,
'show_ui'=>true,
'show_in_menu'=>true,
'show_in_nav_menus' => true,
'rewrite' => array('slug' => 'fellow'),
'supports' => array('title', 'editor','thumbnail'),
'has_archive'=>true
);
register_post_type('cima_fellowship', $args);
}
I've created a custom archive in a file called archive-cima_fellowship.php and it works, showing all my cpt.
This cpt have a meta attribute like status, to define some of them as current and other as past. I would like to have two different archive pages, one to show only he current and another to show only the past.
For now I turn around this using a get variable in this way mysite.com/cima_fellowship/?type=past
But I would like to have cleaner url like mysite.com/fellows/past.
For this I defined 'rewrite' => array('slug' => 'fellow'), in the registration of the cpt, but I can't access the archive page trough `mysite.com/fellows, I still have to visit 'mysite.com/cima_fellowship/', and I can't find out how to "style" the URL.
Any suggestion? tutorial? guide?
Thanks in advance!
Now I am not 100% sure if this will work but try adding:
'has_archive' => 'fellow'
So you would have:
function register_cima_fellowship() {
$args = array(
'labels' => $labels,
'public' => true,
'menu_position'=>20,
'show_ui'=>true,
'show_in_menu'=>true,
'show_in_nav_menus' => true,
'has_archive'=>true,
'rewrite' => array('slug' => 'fellow', 'with_front' => false),
'supports' => array('title', 'editor','thumbnail'),
);
register_post_type('cima_fellowship', $args);
}
I had a similar problem 10 or so months ago and I add this and seemed to fix my problem.
This is an issue with WordPress, so long as you have the 'slug' => 'my-slug' argument it will work but you have to first change your permalink structure. Change your permalinks via WorkPress>Settings>Permalinks to a random different structure then back to your previous one.
This should fix the issue.
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.