How do I prevent wordpress from adding number suffix to my URL.
I am trying to have the below two urls, but when I created the Arabic version the number 2 was appended to the first one. Below is what I want
http://site-name/en/seven-days
http://site-name/ar/seven-days
But this is what I get.
http://site-name/en/seven-days-2
http://site-name/ar/seven-days
I understand that this was added to wp
The pages need to have the same slug at least, even if the title should be different.
The WP engine wants unique post names and will always append a number to achieve that. You'll need to use a custom permalinks plugin to get what you want. Here's an example of someone with the same issue, working around it with a permalink plugin: https://wordpress.org/support/topic/polylang-share-same-slug-between-languages/
Related
I have 1 custom table (not wp core table) where are specific products imported. I've set up custom wp page where these products are listed, custom filter created etc. In this step so far everything is OK - products are listed and filtering works, pagination works...
But what I want to extend further now - open each product page (like /product-listing-page/product-name-1) when clicking on product names in product list page... How can be this achieved "out of wp_posts" table?
Why I'm not using wp_posts table: web site have static pages and dynamic posts as news and product table is truncated and re-imported once in a day every night! So, can not really use wp_posts page when product list is dynamic and totally truncated before each import...
Any ideas? Maybe anybody already did such stuff?;-)
I don't know if you developed a plugin to handle all the custom table and code you created, but if you didn't, I strongly encourage you to do so.
Because by making your code as a plugin, you have the oportunity to use all the composants of wordpress, like the rewrite rules system, which, I think, could help you to achieve your goal.
I created a plugin some times ago for a website I have the charge and I needed a custom page to be displayed within the website (worpdress) url system, which is what you want to do if I correctly understand your question.
Unfortunately the plugin has evolved since and I didn't keep a backup of that code, but if I remember correctly how I did it back when, here is the rough approach I followed:
I create a plugin which handle :
custom db table(s)
custom php objects
...
AND (this is the intersting part) add rewrite rule to wordpress rewrite rules system as follow:
set rewrite tag (init action) (if needed)
add rewrite rule (init action)
intercept url and parse it to get the params i need in my custom
page (parse_request action)
The following functions may help you with that :
add_rewrite_tag
add_rewrite_rule
And you need to hook in :
init
parse_request
Hope it helps you start.
the solution was quite quick and easy! For my needs it was enough just to register global query var:
function register_new_query_var($vars) {
$vars[] = 'product_id';
return $vars;
add_filter('query_vars', 'register_new_query_var');
and then I changed theme template for page product-listing-page to work for product listing and individual products with using
if(!get_query_var('product_id')). So, if query empty - do listing stuff, if not empty - do individual product stuff!
For me this is quite enough and I do not need even seo friendly urls (because product list changes every day, so - every day will be new products, links, and there will be to much 404 errors)...
and I can use http://example.com/product-listing-page?product_id=1 and page displays with date which is from custom table! ;-)
Is it possible to have the following structure, and if so, how:
www.example.com/something (A custom archive page with posts from a certain post category ['poca'] and a certain custom post type ['cuty'])
www.example.com/something/beautiful (A post of category ['poca'])
www.example.com/something/ugly (A post of my custom post type ['cuty'])
I can achieve to get my custom archive page to work. Moreover everything works so that 'poca' and 'cuty' takes the same template. But coming from something to one of these posts, it takes the normal permalink (category-name or custom-post-type) instead of something
Is there a way to achieve that it takes my custom archive page into the url instead?
By the way: I am able to achieve the result by using a custom shortcode for my custom post type and then creating a new post with that shortcode in the wanted category, but this brings a consistency problem, as there's always the need to create two posts for the one thing I'd like to have.
So I finally found a solution. Seems not the best way but it's ok for me to do it this way...
Through using the plugin "Custom Permalinks" I can add the permalink I want, so I only need to add something for all my new posts in that category and all new posts of my custom post type. But I am still searching for a solution which does that part automatically if somebody knows...
I'm working on a Wordpress project and have a question.
I have a layout like shown below in the link to screenshot with a select field and boxes with news (two or more different post types). I want to filter with the select the post type so there should show up only the selected. How can i do that?
Thanks in advance.
If you're fine dropping the pagination and having all of your posts on a single page, one option is to use Isotope.js. In addition to being a very useful plugin, they have thorough documentation to figure out how to structure your code to get filtering working.
If the pagination is absolutely necessary, this becomes more complex. Here's the short hand-wavey version that needs testing: You can use JS to reload the page with an extra parameter added to the URL (ex: /your-page?filter=post_type_1). You'll need to register your custom URL parameter with WordPress. Then, in your PHP, you'll use that parameter data in your WP_Query (or whatever you're using to query posts) to grab only posts of that type. It would be smart to have a default, where if the filter parameter from the URL isn't present or doesn't match a post type you have in your site, you default to showing all posts.
This blog post walks through how to do this method of filtering more thoroughly: https://codepen.io/the_ruther4d/post/custom-query-string-vars-in-wordpress.
I'm trying to ensure the WordPress site I'm working on maintains consistent URLs. The problem I'm having is with child pages and custom post types.
Essentially the setup is as follows.
/main-page/sub-page/
Main Page
-- Child Page
This is fine, however I have a custom post type (research-papers) I'd like to list on the Child Page. I've got this working fine. The problem I'm having is getting the research papers post type to use the following URL structure:
/main-page/sub-page/research-paper-title/
I've looked at wp_rewrite_rule but I can't get anything working. Any ideas?
add_rewrite_rule(
"main-page/sub-page/([^/]+)/?",
"index.php?research-paper=$matches[1]",
"top"
);
Change the first parameter from
"main-page/sub-page/([^/]+)/?"
to
"main-page/sub-page/([.]+)/?"
The way it's set up now, you are searching for the pattern "main-page/sub-page//...", with 2 forward slashes after "sub-page", which isn't going to catch anything.
I have a custom posttype in Wordpress 3. I would like to every post of this type to have the option to add a link. Basicly this will be a link that refers to another page/post whatever on the site.
There should be only one link for each post of this type. And i would then need to extract this link in my template files. Basicly im creating a post-type "Slideshow" And each slide-item should be connected to one page or post. So when you click a slide you will be taken to the defined page.
i know i can do this by using a custom-field. But then i would need to enter the whole url every time. I would like a feature similar to that of the wordpress WYSIWYG editor link button. So i can add a link to "existing content" easy.
Anyone know of any tutorials or similar on how to do this?
Thanks!
bit surprised no one has mentioned this plugin "Related Links"
Wordpress plugin Related Links
It adds a metabox to your edit forms. You can link to related content or put in external URL.
It allows links to posts, pages, media AND Custom post type - check its type on the Settings page of the plugin after install. It uses a similar search/browse facility to the normal WYSIWYG link insert feature!
What post-types does it apply to? If you are using on a custom post type, then check all the post-types you want to be able to link to - it still shows the box on this post-type itself.
It can accept multiple links, but one will work of course. Then you use the get_related_link() function in your template to output this and format as you like.
If you just want to make a link between the two posts, rather than insert it in your post content, I'd recommend the Posts 2 Posts plugin. It'll allow you to create links between posts without having to remember the full URL.
Edit:
I haven't used it, but I suspect the cardinality argument should help you limit the number of links - see the wiki.
And you can certainly access the connections in your templates - I have. Once you've registered your connection type, you can just call get_connected:
$venue_details = p2p_type( 'exhibition_to_venues' )->get_connected( $post->ID, array(
'posts_per_page' => -1,
'connected_orderby' => 'order',
'connected_order' => 'ASC' )
);
It seems to me that the best method to accomplish this would be to add a custom meta box to all posts and post types (see here:http://themefoundation.com/wordpress-meta-boxes-guide/). Within this meta box, you can simply query all posts that you would like to include in a dropdown. You can then select the post from that dropdown, obtain the ID of the post selected (use as data attribute in the option field), and then return the permalink for that ID. This will then allow you to simply select the post, rather than having to know the actual URL each time.
Another method would be to attach a piece of unique data to x post (most likely utilizing custom fields), and then also attach it to y post. In this way, you could use a function to automatically append the link to the displayed post. You would do this by querying the posts in the database, match the custom data, and if matched, display the link to that post. This would allow the entire thing to be automated, and you wouldn't even have to select anything. In my opinion, the title field should actually be sufficient for this, since both posts are different post types (you should be able to title them the same), and would likely make your query a bit easier/shorter since you would simply need to find the post that matches the title, and then link to the permalink.
I can elaborate on all of the above further, with code samples as well, but in my opinion, the question is slightly too vague to write a custom script example for this scenario.
I would hope the above would be sufficient to get you going.