Forums › Forums › Search & Filter Pro › Serialized Post Meta
Tagged: post meta, serialised data, woocommerce
- This topic has 3 replies, 2 voices, and was last updated 8 years, 11 months ago by Ross.
-
Anonymous(Private) December 10, 2015 at 6:13 pm #31926
Hi There,
I’m having an issue when trying to filter an post meta with nested arrays.
a:1:{i:0;a:6:{s:4:”name”;s:5:”Meses”;s:11:”description”;s:0:””;s:4:”type”;s:11:”radiobutton”;s:8:”position”;i:0;s:7:”options”;a:9:{i:0;a:4:{s:5:”label”;s:7:”Janeiro”;s:5:”price”;s:2:”10″;s:3:”min”;s:0:””;s:3:”max”;s:0:””;}i:1;a:4:{s:5:”label”;s:6:”Março”;s:5:”price”;s:2:”10″;s:3:”min”;s:0:””;s:3:”max”;s:0:””;}i:2;a:4:{s:5:”label”;s:5:”Abril”;s:5:”price”;s:2:”10″;s:3:”min”;s:0:””;s:3:”max”;s:0:””;}i:3;a:4:{s:5:”label”;s:4:”Maio”;s:5:”price”;s:2:”10″;s:3:”min”;s:0:””;s:3:”max”;s:0:””;}i:4;a:4:{s:5:”label”;s:5:”Junho”;s:5:”price”;s:2:”10″;s:3:”min”;s:0:””;s:3:”max”;s:0:””;}i:5;a:4:{s:5:”label”;s:5:”Julho”;s:5:”price”;s:2:”10″;s:3:”min”;s:0:””;s:3:”max”;s:0:””;}i:6;a:4:{s:5:”label”;s:6:”Agosto”;s:5:”price”;s:2:”10″;s:3:”min”;s:0:””;s:3:”max”;s:0:””;}i:7;a:4:{s:5:”label”;s:8:”Setembro”;s:5:”price”;s:2:”10″;s:3:”min”;s:0:””;s:3:”max”;s:0:””;}i:8;a:4:{s:5:”label”;s:8:”Novembro”;s:5:”price”;s:2:”10″;s:3:”min”;s:0:””;s:3:”max”;s:0:””;}}s:8:”required”;i:1;}}
This above is the serialized data.
It’s a basic select of months inside a woocommerce product.
Can you guys guide me on this.
Thanks in advance
Ross Moderator(Private) December 13, 2015 at 10:55 pm #32117Hey Felipe – is this data you are saving in some kind of custom function?
Thanks
Ross Moderator(Private) December 15, 2015 at 12:06 pm #32234Possibly – there are few issues here to consider
It looks like you might be nesting the data too much.
For example, you can save multiple values to one meta key – so you wouldn’t need one object like that, you would have separate entries for your options under a different key just for options:
https://codex.wordpress.org/Function_Reference/add_post_meta
Take a look at the unique option.
In addition to this, the key you want searching contains a bunch of other info you do not want to be searched such as
name
,description
,radiobutton
etc – so the format here is not correct – labeling and field data should be stored in a different key, and your data in anotherEven with the above, I think there is still too much nesting.
Even if S&F is able to search inside this field, semantically I can’t see how you would search this field.
In search and filter, you can create a field, and this field is bound to 1 meta key. So it would look in all that data, prices, label, min, max etc
So if you choose to use this key to create a dropdown, then what kind of data is it searching? You will be trying to use 1 dropdown to search all that data. To me it doesn’t really make sense, but then again I do not know your use case.
What I would recommend to do is use either the WP Types plugin, or Advanced Custom Fields plugin to try to achieve what you want.
By all means, remove them after some testing, but use them initially to observe how they are storing the data and the kind of relationships the post meta can have with the post itself.
Hope that helps.
Thanks
-
AuthorPosts