Tagged: relationship field woo commerce
- This topic has 7 replies, 2 voices, and was last updated 3 years, 6 months ago by
Steve.
-
AuthorPosts
-
-
May 18, 2018 at 3:21 am #8994
levipeParticipantHi,
I’ve just migrated woocommerce to 3.3 and piklist to 0.11.1
I have a couple of related fields that were working fine before that migration.
Since migration, its impossible for me to link products to articles in content-types I’ve created. They do appear on the admin product but ticking the boxes doesn’t help creating the relationships. They are not saved.
-
June 3, 2018 at 6:02 pm #9034
levipeParticipantup
-
June 4, 2018 at 4:34 pm #9040
SteveKeymasterPlease post your field code here: https://gist.github.com/
-
July 22, 2018 at 7:02 am #9138
levipeParticipantSo,
I got it working… half.
The parts-code looks like this:
piklist('field', array( 'type' => 'checkbox', 'label' => 'Regions', 'choices' => piklist( get_posts( array( 'suppress_filters' => false, 'post_status' => publish, 'numberposts' => -1, 'post_type' => 'region' )), array( 'ID', 'post_title' ) ), 'relate' => array( 'scope' => 'post' ), 'attributes' => array( 'class' => 'multiple' ) ));and yes, the relationships are stored, like this:
post_ID: 41 meta_key: __relate_post meta_value: 1707post_ID is a post of post_type region and meta_value is a post holding a product.
But, the symmetric relationship is not stored!
post_ID: 1707 meta_key: __relate_post meta_value: 41is not present in the DB.
This hasn’t consequences on my layout (working with has_post and post_belongs as need be), but the queries in WooCommerce don’t work anymore because of the lacking symmetric relationship post. In this instance, I cannot query on ‘region’.
-
July 22, 2018 at 4:48 pm #9141
levipeParticipantSo, this is what I added to the function relate() in class-piklist-form.php to establish the 2-way relationship
add_metadata($object['scope_to'], $from, $meta_key, $to); // added CG 22/7/2018 add_metadata($object['scope_to'], $to, $meta_key, $from);But, it’d be better if Steve could add that to the core code
-
July 25, 2018 at 11:13 am #9153
SteveKeymasterWe updated the relate code recently. The docs go over how to use relate in detail:
https://piklist.github.io/docs/tutorials/relationships/working-with-field-relationships/ -
July 25, 2018 at 11:17 am #9154
levipeParticipantYes Steve,
I understand the code has been altered.
But, as I wrote, this creates issues with the filter in WooCommerce.
A related field in a product cannot be filtered with WooCommerce anymore.That’s why I suggested the above modification to the code.
C
-
July 25, 2018 at 12:53 pm #9159
SteveKeymasterIf you look in the tutorial towards the end it says this:
“So if you look at the book’s meta, you won’t see anything added about the chapter. Why? Because it’s not designed to put anything there. Look at the chapter’s meta. You should find it there. For this reason, you don’t need to specify a field, as relate fields are a special type which store in their own way. In short, the owned object stores the meta.”You need to use
'relate' => 'belongs'and'relate' => 'has'
-
-
AuthorPosts
- You must be logged in to reply to this topic.