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

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.

Related

Wordpress automatically created a redirect that I need removed

I made an edit to a page on a Wordpress site that included changing its parent. Unfortunately I was not paying attention and this move somehow changed the permalink/slug which I saved before noticing. In addition Wordpress automatically created a 301 redirect to go from the original URL to this new URL. I went back in and changed the permalink/slug back to the original but that redirect still stands so it stills sends the page to the new url it created rather than keeping it to updated option (updated meaning me typing in the original slug).
I am looking for a way to remove the 301 redirect, but do not know where to start.
The original URL: https://www.synergex.com/rev11
The newly generated URL: https://www.synergex.com/products/synergy-de-rev11-licensing-faq
I also tried simply creating a brand new page using the original slug/permalink /rev11 but it gets changed to /rev11-2 so it seems like it it must remember the /rev11 somewhere.
I am hoping there is a way to do this through the WP Dashboard and am open to suggestions. This site does have the Redirection plugin installed but I've checked through the lists and this redirect was not created or listed in it. I also tried to add a redirect to do the opposite (redirect from the new URL to old) but of course it just created a loop that timed out.
EDIT 1.2: You probably have a problem with your old permalinks not getting flushed properly. But do not worry the great people at Wordpress got a function for that called flush_rewrite_rules();
Remove rewrite rules and then recreate rewrite rules. This function is
useful when used with custom post types as it allows for automatic
flushing of the WordPress rewrite rules (usually needs to be done
manually for new custom post types). However, this is an expensive
operation so it should only be used when necessary.
Source # https://developer.wordpress.org/reference/functions/flush_rewrite_rules/
Add the following to the top of your function.php:
<?php
/**
* Removes a function from a specified filter hook.
* More about flush_rewrite_rules(); # https://developer.wordpress.org/reference/functions/flush_rewrite_rules/
*/
flush_rewrite_rules();
/*
* Remove rewrite rules and then recreate rewrite rules.
* More about remove_filter(); # https://developer.wordpress.org/reference/functions/remove_filter/
*/
remove_filter( 'template_redirect', 'redirect_canonical' ); ?>

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

How to make your own post format in Wordpress?

How can I create my own custom post formats?
Or how can make my custom post type make work with a function like
get_post_format();
For example i have a custom-post type with the type of "accordion" and i like to be able to use it with as content element in the loop, but only if it exists...
get_template_part( 'content', get_post_format() );
So i am looking for a function like
get_custom_post_format();
which does not exists in Wordpress.
Anybody tried something similar?
I'm not sure if you're asking how to create custom post formats or custom post types so I've provided the answer to both.
If you're asking whether you can create custom post formats...
...then the answer is no. See the quote below from Post Formats on the WordPress codex:
The Post Formats feature provides a standardized list of formats that are available to all themes that support the feature. Themes are not required to support every format on the list. New formats cannot be introduced by themes or even plugins. The standardization of this list provides both compatibility between numerous themes and an avenue for external blogging tools to access this feature in a consistent fashion.
If you're asking how to create a custom post type:
The most basic example of creating (registering) your own custom post type is to add the following code to your functions.php file inside your theme.
function register_recipes_post_type() {
$args = array( 'public' => true, 'label' => 'Recipes' );
register_post_type( 'recipe', $args );
}
add_action( 'init', 'register_recipes_post_type' );
The above code hooks our register_recipes_post_type function to be executed when the init action is triggered by WordPress core.
Once you've added this code, if you go to your wp-admin you'll see a new menu on the left called 'Recipes', that's your new custom post type. If you add a new recipe, give it a title and some content, publish it and then try to preview it, you'll notice that you get a 404 error. After creating a new custom post type you need to go to your Settings > Permalinks in your wp-admin, just visiting that page will fix your permalinks to include the new custom post type so if you now go back and refresh the preview of the recipe you just created you'll see that it now works rather than 404s.
Now if you create a new file called single-recipe.php and put some code inside it, just put 'test' now for the purpose of seeing that it works and once you have, refresh the preview of the recipe you just created once again and you should see that it just displays the word 'test'. Using that file you can create a completely custom template to be displayed for showing single entries (posts) of that custom post type, or you could use content-recipe.php if your single.php includes a get_template_part( 'content', get_post_format() ); as you said in your original post.
Obviously your custom post type probably won't be for recipes but just update instances of recipe and recipes to whatever you want it to be.
There are also other post type specific templates you can create too for your archive of the post type etc. The above should be enough to get you started though.
There are also other arguments you can pass when registering your post type, you can see the full list here: http://codex.wordpress.org/Function_Reference/register_post_type
I hope this helps. Good luck! =)
Creating New post format is not allowed currently by WordPress. you can’t define any post format apart from what WordPress allows.
Reference:
1. http://wp.tutsplus.com/tutorials/proof-using-post-formats/

wordpress - Issue With custom post types and permalinks

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),
//...
));

Resources