Support

Account

Home Forums Backend Issues (wp-admin) Multisite cross-site post selection

Unread

Multisite cross-site post selection

  • This is a discussion in two parts.
    First is a piece of code for getting CPTs from another Site on a Multisite Network
    The second is a call for ideas on how I can filter this dynamically (like the Relationship field)
    The custom post type is called partner and the Select* field to load it into is called site7_partners

    This was implemented as a Relationship field around 10 years ago and, although I did find that code, it no longer works.

    
    function acf_load_partner( $field ) {
    
        $field['choices'] = array();
      
        switch_to_blog(7);
    
        $args = array(
            'post_type' => 'partner',
            'posts_per_page' => -1,
            'post_status' => 'publish',
            'orderby' => 'title',
            'order' => 'ASC',
        );
    
        $page_query = new WP_Query($args);
    
        if ($page_query->have_posts()) {
            while ($page_query->have_posts()) {
                $page_query->the_post();
                $field['choices'][get_the_ID()] = get_the_title();
            }
        }
    
        wp_reset_postdata();
        restore_current_blog();
        // return the field
        return $field;
    }
    
    add_filter('acf/load_field/name=site7_partners', 'acf_load_partner', 999, 1);
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.