Forums Forums Search & Filter Pro Repeatable meta data fields

Viewing 7 posts - 1 through 7 (of 7 total)
  • Anonymous
    #1094

    Is there support for repeatable meta data fields?

    Maybe something like this:
    repeating fields

    The example above has all items in a single row placed into one meta key, but each column could be separated out too. Hope that makes sense.

    Ross Moderator
    #1095

    Hi Hugh

    Is this the ACF repeatable fields?

    Thanks

    Anonymous
    #1126

    Hi Ross

    No, I don’t believe I know what ACF is. What I’ve done above is custom code to output the meta box.

    I maybe mis-spoke slightly in the post above. Instead of each row in it’s own meta key, the entire meta box is in one meta key. When pulled from the database, the array looks like this:

    Array
    (
        [titles] => Array
            (
                [0] => Title1
                [1] => Title2
                [2] => Title3
                [3] => Title4
            )
    
        [folders] => Array
            (
                [0] => folder1
                [1] => folder2
                [2] => folder3
                [3] => folder4
            )
    
        [ranges_b] => Array
            (
                [0] => 55
                [1] => 65
                [2] => 75
                [3] => 80
            )
    
        [ranges_e] => Array
            (
                [0] => 155
                [1] => 165
                [2] => 200
                [3] => 180
            )
    
        [levels] => Array
            (
                [0] => 3
                [1] => 3
                [2] => 2
                [3] => 2
            )
    
        [xtimess] => Array
            (
                [0] => 3
                [1] => 4
                [2] => 2
                [3] => 4
            )
    
        [tapsin3s] => Array
            (
                [0] => 0
                [1] => 1
                [2] => 1
                [3] => 0
            )
    
        [clickss] => Array
            (
                [0] => 1
                [1] => 0
                [2] => 1
                [3] => 1
            )
    
        [techniques] => Array
            (
                [0] => flams,doubles
                [1] => flams,diddles
                [2] => 
                [3] => 
            )
    
        [authors] => Array
            (
                [0] => Padchops
                [1] => Padchops
                [2] => Padchops
                [3] => Padchops
            )
    
    )

    I don’t have to have it structured this way, could just be a single array instead of nested. I suppose what I’m after is support for retrieving arrays from the database.

    Oh, in this example, I only need to be able to search/filter the “titles”, “levels”, “techniques” and “authors”.

    Thanks
    Hugh

    Ross Moderator
    #1128

    Hey Hugh

    Yeah unfortunately you probably won’t be able to do that effectively.

    You mention the data is all in one key, which means all those values are serialized – effectively, in the database all those values are one big string.

    Even in PHP/MySQL you cannot search a field like this properly, you can compare a string or value to see if it exists in a meta key, but you cannot then search the sub arrays or keys specifically…

    Basically your packing in a lot of data in to a single element stored in the database, to get this all searchable you will need to break it out in to separate meta keys, or what is even more efficient for searching are taxonomies.

    * Just a quick note, you can only search meta keys using the range or choice inputs, there is not text searching (yet) so every new title you add, you will need to manually add it to the meta field in the search form (I’m just mentioning this because it looks like free text input).

    I would suggest trying something like this:

    Keep all the rest of the data in the same key, but break out levels and titles in to their own keys…

    Then you will be able to search in the titles, so lets say you have a post with the meta key:

    sf_titles which is an array of any titles you add…
    So sf_titles would (in your example) be the following array:

    [sf_titles] => Array
    (
        [0] => Title1
        [1] => Title2
        [2] => Title3
        [3] => Title4
    )

    And in the database it is actually stored something like:
    'sf_titles' => 'a:4:{i:0;s:6:"Title1";i:1;s:6:"Title2";i:2;s:6:"Title3";i:3;s:6:"Title4";}'

    Then you could use Search & Filter to search this sf_titles meta key to see if the value is contained, and of course a match would be found for any of the 4 titles mentioned above.

    S & F will use %LIKE% to find it, so it only needs to find a single occurrence of the search value (whatever is selected by the user in the search form) to return a successful hit and match the post with this meta key.

    Hope that helps 🙂

    Anonymous
    #1222

    Hi Ross

    Let me see if I understand you. If I put the titles column in one meta key, sf_titles, that could be searchable with S&F as a text search? I’ll play around with that and see how it goes.

    The way I’ve started to go with some of this is to make separate taxonomies for the ones that need it, in addition to all the meta box elements (this part needs to stay in correct order for page output). I’ll experiment further to see exactly how I want/need to structure everything.

    Much thanks
    Hugh

    EDIT: I re-read your response again and I think I understand what you’re saying about the limitations inherent in database serialization. Again, thanks!

    Ross Moderator
    #1223

    Hey Hugh

    Yeah if you put the titles in a seperate key then it becomes searchable, but its still pretty inefficient and your better off doing as you have mentioned and setting up custom taxonomies where possible..

    WordPress taxonomy queries are optimised so they are fast, efficient and accurate – whereas meta searches are by nature slower, in some of my testing I’ve created complex meta queries and found the page can take many seconds longer to load – so yeah way more inefficient – go taxonomies!

    Let me know how you get on 🙂

    Anonymous
    #1224

    Good info on taxonomy query speeds. Looks like I’ll continue in that direction.

    When I have this all done, I’ll post a link to the live site.

    Thanks
    Hugh

Viewing 7 posts - 1 through 7 (of 7 total)