Open smazur opened 1 month ago
Hi @smazur
Thanks for using the Yoast SEO plugin.
If you reset the Yoast indexables, will the og:url meta tag be updated after completing the reindex? More info about resetting the indexable at here: https://yoast.com/help/how-to-reset-yoast-indexables/
It seems like the issue you have noticed is due to this one: https://github.com/Yoast/wordpress-seo/issues/15246, which was reported by other users before. However, our development team was not able to replicate it before. So, can you share more details on how to reproduce it with deeper steps on that issue to help us better replicate it and fix it?
Hi @josevarghese
After reindexing the og:url
gets correct value.
Here are the steps you can try to replicate this issue:
$p = new WC_Product_Simple();
$p->set_name( 'Test product' );
$p->set_status( 'publish' );
$p->set_category_ids([ PUT_YOUR_CATEGORY_TERM_ID_HERE ]);
$p->save();
og:url
meta tag value on single product page you just created.This issue is also replicated when i create new product using following wp cli command:
wp wc product create --name='Cli product test' --type=simple --status=publish --categories='[{"id":PUT_YOUR_CATEGORY_TERM_ID_HERE}]' --user=PUT_ADMIN_USER_ID_HERE
Hi @smazur
I tried the WP-CLI command and code but got some errors while checking both on my lab site. When I tried the WP-CLI wp wc product create --name='prdctname' --type=simple --status=publish --categories='[{"id":1013}]' --user=7
, I am getting the error "Error: Invalid parameter(s): categories {"status":400,"params":{"categories":"categories[0] is not of type object."},"details":{"categories":{"code":"rest_invalid_type","message":"categories[0] is not of type object.","data":{"param":"categories[0]"}}}}". So can you please share the code and CLI command correctly?
Thanks in advance.
@josevarghese
On my setup wp cli command works without any error.
Did you try the php code above? You can run it from wp shell
line by line.
I reproduced the issue with the following steps. Also confirmed that adding a post through WP CLI does not experience the same issue.
Starting with a vanilla installation (category permalinks):
wp wc product create --name='CLI product test' --type=simple --status=publish --categories='[{"id":17}]' --user=1
wp post create --post_type=post --post_title='CLI post test' --post_category=87 --post_status=publish
wp post get 1907 --field=url
(Replace ID as needed)og:url
<meta property="og:url" content="http://example.com/shop/uncategorized/cli-product-test/" class="yoast-seo-meta-tag" />
wp post get 1908 --field=url
(Replace ID as needed)og:url
Permalink: /%category%/%postname%/
Woo Permalink: /shop/%product_cat%/
Setup path: /wp-admin/admin.php?page=wc-admin&path=%2Fsetup-wizard
Introduction Uncheck 'I agree to share my data' Click 'Set up my store'
Step 1: Which one of these best describes you? Select 'I'm just starting my business' Click 'Continue'
Step 2: Tell us a bit about your store Enter store name (optionally leave it the domain) Select 'Clothing and accessories' for type of products Select 'United States (US) -- California' for the store location Click 'Continue'
Step 3: Get a boost with our free features Click 'Skip this step' (top corner of page)
Import Products Go to Admin > Products Click 'Start Import' Browse to WooCommerce plugin folder '\wp-content\plugins\woocommerce\sample-data' Select 'sample_products.csv' Click 'Continue' Click 'Run the importer' Wait for success message
Hi @smazur
I re-opened issue #15246 as it is reproducible by my senior colleague Angelia.
Please give us a description of what happened
Hi! We have a WooCommerce store and use custom code to dynamically create products as follows:
Also we have rewrite rules setup that uses category slug and few other attributes in product url. When a new product is created i noticed that
og:url
meta tag has wrong product url.That's because
\Yoast\WP\SEO\Integrations\Watchers\Indexable_Post_Watcher::build_indexable
is hooked directly towp_insert_post
so the index record is created immediately after product post created and before any taxonomy attributes assigned to it. So it makesget_permalink
return wrong url for the product.I think this is a bug and
\Yoast\WP\SEO\Integrations\Watchers\Indexable_Post_Watcher::build_indexable
call should be defferred like you do in\Yoast\WP\SEO\Integrations\Watchers\Indexable_Post_Meta_Watcher::update_indexables
As a quick fix i used following snippet.
Looking forward for you reply. Thanks!