Getting items in metabox which was created by plugin

54 Views Asked by At

i have a plugin and in there team members can be added. its actually a list of some members. now i have created a metabox for pages. in this metabox i want to show those members name in a select box to chose. so that those member will show up in that page. in the metabox code i am trying to get the members like this:

$post_type2 = 'team';
    $orderby2 = 'menu_order';
    $order2 = 'ASC';
    $posts_per_page2 = 100;
    $query2 = new WP_Query( array ( 
        'post_type'      => $post_type2,
        'posts_per_page' => $posts_per_page2,
        'orderby'        => $orderby2, 
        'order'          => $order2,
        'no_found_rows'  => 1
        ) 
    );
    //Get post type count
    $members = array();
    $members2 = array();
    $post_count2 = $query2->post_count;
    if( $post_count2 > 0) :
        while ($query2->have_posts()) :
            $query2->the_post();
            $members2['mid'] = get_the_id();
            $members2['mname'] = get_the_title();
            $members[] = $members2;
            //echo the_id();
        endwhile;
    endif;

but it messing up with the page itself. i can get the members, but the name of the page is changed to member's name. my page is "home" and in the title area, it shows jhon doe - member name. any idea why? i think i am using the wrong "get" method to get the items.

EDITED

The idea:
The team plugin adds some member. I want to show these members in pages. But not same members in all pages. For example: "john doe" can be appear in "about" page but not in "service" page. Like this. Thats why I was thinking of creating metabox in pages to choose members. Is this the right way to do that? Or any other idea??

1

There are 1 best solutions below

0
On

It's not safe to use WP_Query on "edit post" admin pages, as it messes things up and causes unexpected behavior. Switching to get_posts should fix that.