• Hi there!

    I’m stuck on writing PHP using Magic Fields 2, and the support for the plugin doesn’t seem very active. I left this post on their google group just in case, but judging by their past threads, I don’t have high hopes.

    I’m having this issue where I’m in a page template on a normal page. And since MF doesn’t allow more than 1 level of duplicated groups (like ACF), I had to create two custom post types instead.

    Ideally I would have wanted this:

    One Post Type:
    >>>>Duplicated Group:
    >>>>>>>Field 1
    >>>>>>>Field 2
    >>>>>>>Field 3
    >>>>>>>Duplicated Group:
    >>>>>>>>>>Field 1
    >>>>>>>>>>Field 2
    >>>>>>>>>>Field 3

    But instead I had to do this:

    One Post Type:
    >>>>Duplicated Group:
    >>>>>>>Field 1
    >>>>>>>Field 2
    >>>>>>>Field 3

    Second Post Type:
    >>>>Duplicated Group:
    >>>>>>>Field 1
    >>>>>>>Field 2
    >>>>>>>Field 3

    (I just put the >>> since I can’t tab to show the hierarchy.)

    But the groups in the second post type are meant to be related to the first post type. So I’ll need to pull one group in CPT2 per group in CPT1. But I’m getting stuck in the foreach loop of the first CPT and trying to find way to do this? Suggestions?

    https://wiki.magicfields.org/doku.php?id=working_with_groups_duplicated_groups_and_duplicated_fields_v20#duplicate_groups

    I tried to use a for each loop and get_post_meta? But that doesn’t work because I can’t pull out the fields in their assigned group and can’t pull specific fields. Here’s what I have…

    $chall_entries = get_group('challenge_entry', $post_id=4602); //The First Custom Post Type's Group
    
    foreach($chall_entries as $war_task):
              if( $war_task['challenge_entry_challenge_type'][1] == 'Warrior' ):
              //The if statement was the only way I could ensure a specific group in CPT since they're duplicatable
    
                    $war_task_id = intval( $war_task['challenge_entry_assign_task'][1]) ;
                    $war_task_posts = get_post( $war_task_id ); //get ID inserted from CPT group field
    
                    $meta_values = get_post_meta( $war_task_id ); //use this id to get post meta
    
                    echo '<tr>'; //how do I loop through this post meta and still maintain groups in this second custom post type?
                    foreach ($meta_values as $meta_value) {
                      echo '<td>' . $meta_value[1] . '</td>';
                    }
    
              endif;
    endforeach;

    Any thoughts would be much appreciated. I can post more code as well if needed. Thanks! ??

  • The topic ‘Magic Fields PHP help in a page template for 2CPTs/Duplicated groups.’ is closed to new replies.