WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
[resolved] serialized custom fields problem (10 posts)

  1. ivomasterche
    Member
    Posted 1 year ago #

    Hi,

    I've managed to make relevanssi to search in custom fields using relevanssi_do_query(), but it doesn't find posts containing the search term in serialized custom field.

    I am 100% sure that a few weeks ago it was working even without the relevanssi_do_query function, but i guess it stopped after an update, i am not sure when exactly.

    Please confirm that it should work in serialized custom fields too.

    Thank you in advance.

    http://wordpress.org/extend/plugins/relevanssi/

  2. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Please provide more details. Exactly how are you searching custom fields using relevanssi_do_query()? If you're using the hack that sets 'cat' to 'custom' in order to filter by custom field, do note that it was disabled in 3.0. You need Premium to filter by custom field (ie. search for term X in posts with word Y in custom field Z).

    If you don't need filtering, but want just to search custom field content (ie. search for term X in post content or custom field content), that still works with free Relevanssi. If you've set "Custom fields to index" to list the custom fields you want to index (or to "all" or "visible"), you shouldn't need any tricks to fetch posts by custom field content.

    Serialized custom fields should be no problem, as Relevanssi uses get_post_meta() to read the custom fields, and that should unserialize them.

  3. ivomasterche
    Member
    Posted 1 year ago #

    Hi,

    Thank you for you answer.

    I am having an eshop site, which stores some of the custom information of the products in one serialized meta_key in wp_postmeta (like unique article id) and other information in normal custom fields (like price) when i search for that unique id it finds nothing but when i search with data found in the price it shows me the posts.

    It appeared that it is the same with both

    global $wp_query;
    $rq = new WP_Query();
    $rq->query_vars = $wp_query->query_vars;
    relevanssi_do_query($rq);
    in the search.php
    and with the general search.

    I have just updated to the last version - 3.0.4 and i am using Custom fields to index: all

  4. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    I don't know why it wouldn't work. How the serialized meta_key is done? What does it unserialize into? If it's an array, it should work, but if it's an object then yes, it might not get indexed. Can you give me a sample field to experiment on?

  5. ivomasterche
    Member
    Posted 1 year ago #

    Hi, again

    Thank you for keeping in touch.

    I am using a plugin called eshop, which i kind of DON'T recommend and i am not sure how exactly works but the following is one meta key:

    (22350, 8355, '_eshop_product', 'a:8:{s:3:"sku";s:7:"2502062";s:8:"products";a:30:{i:1;a:4:{s:6:"option";s:7:"2502062";s:5:"price";s:6:"102.42";s:6:"weight";s:0:"";s:9:"saleprice";s:5:"66.57";}i:2;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:3;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:4;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:5;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:6;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:7;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:8;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:9;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:10;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:11;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:12;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:13;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:14;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:15;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:16;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:17;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:18;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:19;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:20;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:21;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:22;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:23;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:24;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:25;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:26;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:27;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:28;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:29;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}i:30;a:4:{s:6:"option";s:0:"";s:5:"price";s:0:"";s:6:"weight";s:0:"";s:9:"saleprice";s:0:"";}}s:11:"description";s:17:"Стол Golf GTP";s:8:"shiprate";s:1:"F";s:8:"featured";s:3:"Yes";s:4:"sale";s:3:"yes";s:10:"cart_radio";s:1:"0";s:6:"optset";a:1:{i:0;s:2:"38";}}')

    the format is:

    wp_postmeta` (
    meta_id bigint(20) unsigned NOT NULL auto_increment,
    post_id bigint(20) unsigned NOT NULL default '0',
    meta_key varchar(255) default NULL,
    meta_value longtext,
    PRIMARY KEY (meta_id),
    KEY post_id (post_id),
    KEY meta_key (meta_key)
    ) `

    It should contain all the info including predefined number of variations which if are not fulfilled ... stay empty.

    Since i needed the price for other operations i've made a plugin of my own which unserializes the data and puts it in simple custom field, (that is indexed correctly) by using:

    $eshop_product=maybe_unserialize(get_post_meta( $post->ID, '_eshop_product',true ));
    $duplicate_price = $eshop_product['products']['1']['price'];
  6. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    I tried the example field you posted, and it works - I tried searching for "saleprice" and Relevanssi found it. Relevanssi doesn't unserialize the field, just passes the serialized value for tokenizer, which will then split it into words.

    So, yes, it should work. Are you sure the custom field is being indexed? Since it is a hidden field, setting the custom field option to "visible" is not going to grab it.

  7. ivomasterche
    Member
    Posted 1 year ago #

    Ok, thank you for your efforts.

    In this case i guess it's a collision with some other plugin. I'll try to disable everything, reindex and search.

    How can i check the indexed date ?

  8. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    You can't, it's not stored anywhere.

  9. ivomasterche
    Member
    Posted 1 year ago #

    Hi,

    Unfortunately i couldn't make it work.
    I tried to uninstall and the to install the plugin, tried disabling other plugins but it didn't work.

    It is indexing the posts because i can search for other custom fields, but not for that serialized one.

    Maybe it's something with the eshop plugin, as i said i found that i don't like it very much but too late, after inserting a lot of products. Unfortunately it's not even a single plugin, its needs some 3 or 4 additional plugins making small changes and adding features to the main plugin, so it's quite complicated.

    Thank you once again for trying to help me i'll still continue to use Relevanssi in other projects.

  10. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Ok, probably the other plugin then. That's life with WP, and I know your pain - I had a rather unpleasant membership plugin at Relevanssi.com, took the trouble to switch to another and it's been better - but far from perfect - afterwards.

    Anyway, based on my tests serialized custom fields should work, but the results may not always be what you expect, as Relevanssi does not unserialize the field contents.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags