wordpress - Issue With custom post types and permalinks - wordpress

I'm working with Custom Post Types for the first time and running into a vexing problem:
I can add and query the post types, but they always show up as:
domain.com/post-type-name/post-title
I have no rewrite in place, and my permalink structure is set to %postname% only, and I am flushing the rules immediately following adding the post type.
Any ideas on what I'm doing wrong?

This could be helpful to solve the problem:
http://www.ultimatewebtips.com/remove-slug-from-custom-post-type/

You may try two things
Just visit your Permalink Settings from the settings menu and save the page again.
or you may try
register_post_type('post-type-name', array(
//...
'rewrite' => array('slug'=>'','with_front'=>false),
//...
));

Related

can I have different url for custom post type in frontend and backend?

The question is straightforward. I have custom post type 'project'. In front-end for the project detail page I don't want 'project' to show in url. I mean by default project detail default url will be site_url/project/project_url but I want new url to be site_url/project_url.
I tried
'rewrite' => array(
'slug' => '',
'with_front' => false,
),
but this cause url to be changed in both backend and frontend and also page named "Projects" is throwing 404 error.
Can this be done ? Any suggestions or help is welcome.
I tried to achieve it without using any plugin but I failed. So I used plugin 'https://wordpress.org/plugins/permalink-manager/' and it helped me achieve what I wanted.
Following my comments, in short, it's not the intended initial behaviour Wordpress had in mind. Only posts or page are supposed to display that behaviour. I've just made a couple of test. None of the answer properly works, as they all have impacts on some crucial functionality.
If you're not using single-cpt.php then the accepted answer could worked for you (eg: https://wordpress.stackexchange.com/a/204210/190376) but then again I would suggest you avoid messing up the default permalinks structure.
In any cases, none of the example are talking about flushing rewrite rules upon modify the permalinks structure. Do your tests, tests all answers given in that post (eg: https://wordpress.stackexchange.com/questions/203951/), and add the following to the top of your function.php file.
<?php
/**
* flush_rewrite_rules
* Remove rewrite rules and then recreate rewrite rules.
* #link https://developer.wordpress.org/reference/functions/flush_rewrite_rules/
* Need to be removed before pushing to live.
* Can be replaced on live by: add_action( 'after_switch_theme', 'flush_rewrite_rules' );
*/
flush_rewrite_rules(); ?>
Making sure you're flushing every time is the only way to make sure your testing is accurate.

Wordpress "custom post type permalinks" plugin generates 404 Page not found

I need the links of all personalized posts and taxonomies to be structured with the name of the category (s) they belong to.
Unfortunately the theme used for my site generates a new type of post and the new taxonomy programmatically and performs the rewrite of their permalink.
To solve this problem I configured the "Custom Post Type Permalinks" plugin which works, but only halfway:
- the permalinks of taxonomies are generated correctly and are accessible from the site.
- the permalinks of the posts are generated correctly, but are not accessible from the site and return a page with a "404 Page not found" error.
In my httpd.conf the line LoadModule rewrite_module modules/mod_rewrite.so is not commented.
What can I do?
let me give you a deeper idea about what we’d like to get. We would really appreciate if you could help us reaching it, by letting us know where to operate.
We would like all the tours’ url to be made up like this: www.sitename.com/$category_father/$category_child/$name_of_my_post Moreover, we would like all the tours’ taxonomies url to be made up like this: www.sitename.com/$category_father/$category_child
At the moment your Tourmaster plugin creates the taxonomies and the tours as below:
www.sitename.com/tour/$name_of_my_post
www.sitename.com/tour-category/$category_child
In order to avoid editing the plugin code and prevent any updates conflicts we installed the plugin “Custom Post Type Permalinks”. It partially solves the taxonomies problem and partially the tours one, generating almost correct urls which are unfortunately not reachable.
www.sitename.com/tour/$category-father/$category_child/$name_of_my_post
www.sitename.com/tour/tour-category/ $category_father/$category_child
Referring to the readme.txt file within www.sitename.com/wp-content/plugins/custom-post-type-permalinks/ we could notice the following example code.
register_post_type( 'foo',
array(
"public" => true,
'has_archive' => true,
"rewrite" => ["with_front" => true],
"cptp_permalink_structure" => "%post_id%"
) );
So we edited the Tourmaster plugin code replacing the rewrite array within the file www.sitename.com/wp-content/plugins/tourmaster/include/tour-option.php with the array [“with_front” => true], but we did not get any result. When you saw the url working, it was due to a temporary reset of the CPTP settings.

Wordpress user frontend Plugin Posts listing order by title?

We are using "Wordpress user frontend Plugin" in our site to create, edit posts from frontend.
There we need a feature which is not implemented in the plugin we guess.
We need to show the posts listing by their titles regardless of their creation date.
Can it be possible?if yes, then can please let us know the correct way of using an action hook or filter rather than made the changes directly on the plugin files itself.
Really needed a quick response,already spending a lot of hours for this one.
Thanks,
You'll need to edit the index page, including 'orderby'=> 'title' in the correct place.
A quick google search will find the exact answer you need. Do your research.
finally after going through the plugin(Wordpress user frontend) files.
I got this filter "wpuf_dashboard_query".
applied my necessary changes to it and it worked.
add_filter('wpuf_dashboard_query','wpuf_posts_sort_by_title');
function wpuf_posts_sort_by_title($args){
$data = array_merge($args, array('orderby'=> 'title', 'order' => 'DESC'));
return $data;
}

Change Permalink of content type

I have a wordpress that has several different content types. I have a spanish version of the site, and in some cases I need to change the permalink structure to match the language.
For example, one content type is a product. Currently the permalink structure is as follows:
http://www.example.com/product/product-name/
however I would need to make it:
http://www.example.com/productos/product-name/
I tried to set it in the initial "register_post_type" method under "rewrite". It didn't seem to do anything.
How can I make this change?
Thanks,
Dan
Try specifically setting the "slug" value under "rewrite":
'rewrite' => array( 'slug' => 'productos' )
If it still doesn't work, make sure to flush your WP cache if you have one activated.

How to rewrite URI of custom post type?

The site that I am working on uses the following "pretty" permalink structure:
http://example.com/blog/my-special-post
But for a custom post type my client would like to avoid having a "pretty" slug:
http://example.com/product/142
How can the post ID be used in place of the slug?
I believe that this might be possible using WP_Rewrite, but I do not know where to begin.
I posted the same question on WordPress stack exchange site and received a good solution:
WordPress StackExchange - How to rewrite URI of custom post type?
All of WP's posts/pages, regardless of their type, can be reached via http://example.com/?p=foo, where foo is the post ID.
By default, redirection to a "pretty permalink" takes place though.
On the WP Codex entry for register_post_type() (I assume that's what you're using to set up your CPT, right?), the rewrite argument is described:
rewrite
(boolean or array) (optional) Rewrite permalinks with this format. False to prevent rewrite.
Default: true and use post type as slug
So, using
$args = array(
'rewrite' => false,
// ... whatever else there is
);
register_post_type('product', $args);
should yield what you're looking for.
In the WP admin you can chane the display of the permalinks by going to 'Settings->Permalinks'. To achieve your desired results, set the custom structure to /%post_id%/. Unless you manually edit .htaccess and the WP rewrite rules, I don't think you can achieve a structure where you have the post slug in the URI for one post type, but the ID for another.

Resources