Reverse Query on clonable post metabox

Support General Reverse Query on clonable post metabox

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4177
    BiznetBiznet
    Participant

    Hello !
    I'm currently trying to optimize my calls to the DB, and am blocked on the problem of the cloneable post metabox.

    I was trying to create a get_posts with arguments using compare => "LIKE", "value" => "i:" . get_the_ID() . ";". Unfortunately, the data are stored with the serialize function, which is horrible for this, as the index of the values could be taken in the query as well
    example of a string which cause problem, as I check it for post ID 1 :
    a:7:{i:0;i:13;i:1;i:23;i:2;i:27;i:3;i:37;i:4;i:54;i:5;i:59;i:6;i:99;}

    I saw that a similar issue was called out there :
    https://support.metabox.io/topic/wp_query-with-meta_value-impossible-on-cloned-data-fields-array/

    A simple solution could be to change the serialized data to a json_encode which is less verbose by the way, that way, indexes would be put out for numerical arrays, and a reverse search would be possible.

    Could you please tell me if such a change would be possible, and if yes what would be the ETA for this ?

    Thank you already !

    #4183
    Anh TranAnh Tran
    Keymaster

    Hi,

    The plugin use WordPress mechanism to store the data. And WordPress chooses to store an array as a serialized string, not a json_encode string.

    I suggest you hook to the rwmb_after_save_post hook and store a duplicated value for that specific field.

    Another idea is in the topic that you referred to, but it has an issue with backward compatibility.

    #4184
    Anh TranAnh Tran
    Keymaster

    FYI, I've just added an issue on Github to track this and gather more opinions.

    #4190
    BiznetBiznet
    Participant

    Hi,
    thank you for the github question.
    Your first solution is indeed a good temporary solution !

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Reverse Query on clonable post metabox’ is closed to new replies.