We're moving a site from Umbraco to Wordpress and need to find a way to convert the URLs so they still work. The permalink of the Umbraco site is blog/posts/2015/may/ which doesn't work with Wordpress as, although you can create custom permalinks, you can't get the month name in there, only the month number - so it would be blog/posts/2015/05/ and not the month name May.
If there's not an easy way through Wordpress, how can I rewrite urls to change the month name to the month number?
Please help!
you can try the php function get_month_link
And then just split it with explode
Example:
<?php $date = get_month_link('2004', '10');
$MandY= explode(" ", $date );
echo $MandY[0]; // October
echo $mMandY[1]; // 2004
?>
Reference:
here
I was able to recreate the correct URLs with the following combination of tags under Permalinks > Custom structure:
/blog/posts/%year%/%monthname%/%postname%/
Related
I'm workin on a plugin and I need some help.
Basically, I list some companies on the website and if you click on a company name, you go to the company details page.
I'm not using post types. I have created a custom table into the database.
On the listing page, I have a link that looks like this:
Read more
$value->company_name // I take this from the database
Everything works just fine, except the details page URL.
Now I get something like this:
http://www.website.com/companies/details/?companyname=My%20New%20Company
I use $_GET['companyname'] on the details page and I list the related company details, from the database.
But, I would like the URL to look like this:
http://www.website.com/companies/details/my-new-company
And still be able to get the company name from the URL and retrieve the details from the database.
I hope you can help.
Thank you.
Regards,
AG
Add a new column named slug in the table and remove spaces of that title.
$string = "my new company";
$string = strtolower($string);
$string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
$string = preg_replace("/[\s-]+/", " ", $string);
$string = preg_replace("/[\s_]/", "-", $string);
echo $string;
Output: my-new-company
OR
You can follow this link
https://developer.wordpress.org/reference/functions/sanitize_title/
I am using sanitize_title now and added a new column into the database table, called slug.
Now the links on the companies listing pahe look like this:
http://www.website.com/companies/details/?companyname=my-new-company
Better than
http://www.website.com/companies/details/?companyname=My%20New%20Company
But, if I create the links without a query, I get a 404 page. That is actually normal since those pages don't actually exist.
http://www.website.com/companies/details/my-new-company/
The slug was a good idea but how can I make such URLs work?
Once these kind of URLs work, I can parse the URL, extract the company slug and retrieve the related data from the database.
I guess I have somehow to transform the query URL into a permalink and on the details page I have to extract the query from the URL.
Hi I am looking how to get a permalink to a woocommerce my account page endpoint. For example edit-address or orders.
I tried this which I know can't possibly be right, it also appends a 0 onto the end of the link.
get_permalink( get_option('woocommerce_myaccount_page_id') )+"orders";
You should use wc_get_endpoint_url(), it will get endpoint value you set in Woocommerce settings so if you change it one day, your URLs will be updated.
wc_get_endpoint_url('orders', '', get_permalink(get_option('woocommerce_myaccount_page_id')))
Available endpoints are :
view-order
edit-account
dashboard
orders
downloads
edit-address
payment-methods
customer-logout
Replace your code with this
get_permalink( get_option('woocommerce_myaccount_page_id') ) . "orders";
PHP concatenation is dot symbol not plus symbol. https://stackoverflow.com/a/1866194/1593365. Your code seems right only
I get this error on my default WordPress feed: pubDate must be an RFC-822 date-time: Mon, 30 Nov -0001 00:00:00 +0000
Anything inherently evil in pubDate? And if so how to solve the problem?
If you look at the two occurrences of the error from Feed Validator, it's only happening because of the oldest two posts in the feed. Every post after that has the correct pubdate specification. WordPress itself follows the specification, but those two posts are missing the year.
This answer might be of use, as it's what's occurring in your posts
There are 4 dates stored for each WP post: Post_date, post_date_gmt,
post_modified and post_modified_gmt. I recommend you to insert the
same date for both post_date and post_modified and see if it works.
That worked, thanks! It was just the post_date_gmt field that needed
to be set.
If it's just those two, you can manually edit them in the wp_posts table in your database if you feel comfortable doing so, or there are various plugins available that can help with doing such a thing.
PSA: Always have a backup of your database before fiddling with it.
Upgrage your plugins with newer version here https://wordpress.org/plugins/wordpress-seo/
because there is a bug
https://github.com/Yoast/wordpress-seo/issues/525
but if it has not been solve your problems, then better you remove this two post
your.url/cliff-diving-boracay-philippines
your.url/bora-bora-activities-snorkeling-hibiscus
or make new version of those.
Try this .. might work
Go into your wp-includes directory and edit the feed-rss2.php file.
Replace this (line no : 89):
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
With this:
<pubDate><?php echo mysql2date('r', get_the_time('Y-m-d H:i:s')); ?></pubDate>
And also try to update the Post for which the date is wrong :
post ID = 17624 and 17637 or see the published date of these posts in edit screen
I need help with this: I need that the url of the downloadable products link with an external url. I´m trying to add a custom field and replace the filters woocommerce_product_file and woocommerce_product_file_download_path but it didn't worked, I think because I can´t call to the product data from the order. Someone did this? Thank you for your help!
The code doesn't works. Now is something like:
*function mostrar_campo_personalizado_en_order($file_id){
global $wpdb, $woocommerce;
echo get_post_meta($file_id, 'downloadable_url', true);
}
add_filter( 'woocommerce_product_file', 'mostrar_campo_personalizado_en_order', 10, 1 );
add_filter( 'woocommerce_product_file_download_path', 'mostrar_campo_personalizado_en_order', 10, 1 );*
I don´t know if I´m working in the correct way, I need to change the url of the downloadable products because woocommerce internally routed. Because I couldn't modify him, I intente removal and display a custom post field. The page is in a test server because the site is on line. The url of the tester server ishttp://lab.jus.raffles.com.ar/my-account/ but you need credential to come in:
user: paula
pass: 5VPeGgAHWzYX1T
OK it might sound stange but I am facing a good challenge with wordpress.
when echoing the_permalink(); and checking the portfolio pages, I am getting a link something like this:
http://www.domain.com/?portfolio=test
(Where test is the portfolio name).
Is there any option to return the permalink trimmed to ?portfolio=test keeping out the domain url?
While asking, I think I got the answer already (trim()) but I would like to hear your ideas too.
every answer will be much appreciated!
You can obtain the permalink of a post by doing something like so:
<?php
function my_permalink() {
echo substr(get_permalink(), strlen(get_option('home')));
}
?>
The get_option method replaces the deprecated get_settings method, and allows you to retrieve named option values from the database:
http://codex.wordpress.org/Function_Reference/get_option
The 'home' value passed in to the get_option method will return the site URL.