Support

Account

Home Forums ACF PRO ACF and author.php loop customization

Helping

ACF and author.php loop customization

  • I use ACF Pro and the field repeater for ‘multi-author’. If there’s more than one person who work on an article, editor must click special checkbox and then repeater appear.

    There are two subfields in the repeater. ma_usr(relation, users) and ma_func (text field).

    Now I want to modify the author loop to add multiauthoring support.

    I found and make query like this:

    
    $query = "
    SELECT $wpdb->posts.*
    FROM $wpdb->posts, $wpdb->postmeta
    WHERE
        $wpdb->posts.ID = $wpdb->postmeta.post_id
        AND $wpdb->posts.post_status = 'publish'
        AND $wpdb->posts.post_type = 'post'
        AND $wpdb->posts.post_date <= NOW()
        AND (
            $wpdb->posts.post_author = $curauth->ID
            OR (
                $wpdb->postmeta.meta_key = 'ma_usr'
                AND $wpdb->postmeta.meta_value = $curauth->ID
            )
        )
    GROUP BY $wpdb->posts.ID
    ORDER BY $wpdb->posts.post_date DESC
    ";

    I need a help with modify this query to get posts with field like ma_repeater_0_ma_usr, ma_repeater_1_ma_usr, ma_repeater_2_ma_usr etc not just ma_usr but i have no idea how to do this.

    I’m not best at SQL tbh. Maybe regex?

  • the meta key where the user ID is stored will be "{$repeater_name}_{$row}_{$sub_field_name}", so there will be a different meta key for each row. You’re going to need to do a regular expression, I don’t know what the regex is for MySQL but for php it would be /^repeater_name_[0-9]+_sub_field_name$/

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

The topic ‘ACF and author.php loop customization’ is closed to new replies.