• Resolved Brickbucki

    (@brickbucki)


    Hi,

    first of all: Thanks a lot for this plugin – I am using it in a lot of diffent ways on my website and never had any mentionable problems. But as time went by, I came across my first major problem … and here it is.

    I’ve been using Types quite a while now. There, I created a custom post-type. It has a custom repeating field named wpcf-part_id. Now, I want to use the values per post to build an external link to every part for every post – kind of this:

    Post A
    <ul>
    	<li>http://lorem.ipsum/part_id[0]</li>
    	<li>http://lorem.ipsum/part_id[1]</li>
    	<li>...</li>
    </ul>
    
    Post B
    ...

    I guess I have to use [array user-field=wpcf-part_id] inside the post loop, as nothing else seem to work. By now, i have:

    [loop taxonomy=category term=A field=wpcf-B value=C compare=and orderBy=field_num key=wpcf-D order=ASC]
    
      <strong>[field title]</strong>
      [array user-field=wpcf-part_id]
        [field wpcf-part_id]
        <br />
        [pass field_loop=wpcf-part_id]
          lorem {FIELD} ipsum
        [/pass]
        <br />
        [pass field=wpcf-part_id]
          lorem {FIELD} ipsum
        [/pass]
      [/array]
    [/loop]

    … which is resulting in …

    Title A
    3956, 93274, 42446, 2436, 44728, 99780, 99781, 99207, 98287, 2422
    lorem 3956 ipsum
    lorem (Array) ipsum
    
    Title B
    ...

    How can I separate the array values properly and process them all? The field_loop-try seems close, but it just returns the first value.

    Thanks in advance
    Tobias

    https://ww.wp.xz.cn/plugins/custom-content-shortcode/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    I’m not familiar with how Types repeating field is stored, but from what you described, it looks like you may be able to get individual values like this:

    <ul>
    [array wpcf-part_id]
      <li>http://lorem.ipsum/[field value]</li>
    [/array]
    </ul>

    If that doesn’t work, could you tell me the output of the following?

    [array wpcf-part_id debug=true][/array]
    Thread Starter Brickbucki

    (@brickbucki)

    Hi,

    I didn’t know the keyword value – but still, it doesn’t work. I wrote this:

    [array user-field=wpcf-part_id debug=true]
      [field value]
    [/array]

    … the output:

    ArrayArrayArrayArrayArrayArrayArray

    … and here the output:

    Array
    (
        [_thumbnail_id] => Array
            (
                [0] => 766
            )
    
        [_edit_last] => Array
            (
                [0] => 4
            )
    
        [_edit_lock] => Array
            (
                [0] => 1444583759:4
            )
    
        [wpcf-anzahl-steine] => Array
            (
                [0] => 1
            )
    
        [wpcf-part_id] => Array
            (
                [0] => 3956
                [1] => 93274
                [2] => 42446
                [3] => 2436
                [4] => 44728
                [5] => 99780
                [6] => 99781
                [7] => 99207
                [8] => 98287
                [9] => 2422
            )
    
        [_wpcf-part_id-sort-order] => Array
            (
                [0] => a:10:{i:0;i:7780;i:1;i:7781;i:2;i:7782;i:3;i:7783;i:4;i:7784;i:5;i:7785;i:6;i:7786;i:7;i:7787;i:8;i:7788;i:9;i:7789;}
            )
    
        [wpcf-min_parts] => Array
            (
                [0] => 1
            )
    
    )

    I need the part in subarray [wpcf-part_id] – how do I get there?

    Plugin Author Eliot Akira

    (@miyarakira)

    OK, so we’re getting closer.

    The user_field parameter is for getting user profile fields, and there is no “user-field” parameter. So, probably the above result is showing all fields for that post.

    From what you posted, it looks like this should work:

    [array wpcf-part_id]
    [field value]
    [/array]

    If not, can you try the following to see if it is getting the field?

    [array wpcf-part_id debug=true][/array]
    Thread Starter Brickbucki

    (@brickbucki)

    I tried the following

    [array wpcf-part_id]
      [field value]
    [/array]
    
    [array wpcf-part_id debug=true][/array]
    
    [array wpcf-part_id debug=true]
      [field value]
    [/array]

    Each of them is printing the first – and only the first – number in the array (which is 3956) … without any debugging info in each case.

    Just inserting [array debug=true][/array] results in the same infos as shown above, in the previous post of mine. I changed nothing.

    And yes, user-field doesn’t exist, dear me – I guess that’s why it’s the only command that worked with debugging … because in fact, it’s the same as simple [array debug=true][/array] then 😀

    Plugin Author Eliot Akira

    (@miyarakira)

    OK, one more try: how about this?

    [array wpcf-part_id each=true]
      [field value]
    [/array]
    Thread Starter Brickbucki

    (@brickbucki)

    Jeeehaaa, I finally got it:

    [array]
      [-array wpcf-part_id each=true]
        lorem [field value] ipsum
      [/-array]
    [/array]

    Thanks a lot for your help – now I can keep on doing magic with this cool plugin 🙂

    Plugin Author Eliot Akira

    (@miyarakira)

    Woo, good to hear.

    That’s interesting that you had to use nested arrays. I guess the first one without any parameters is getting all fields as an array – I’ve never used it that way, and didn’t know the shortcode did that..! Then the second array targets the field you need.. It seems like it could be made simpler somehow, so I’ll look into it.

    Also, I’ll try to improve the documentation about using [field value] for arrays that are not key-value pairs.

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

The topic ‘Loop at repeating wpcf-field with [array] and [pass]’ is closed to new replies.