Question

I just added a meta_box to my custom post_type in wordpress and my two extra wp_editors just dissapears.

I have code like this:

$args = array(
            'post_type' => 'attachment',
            'post_status' => 'any',
            'posts_per_page' => -1,
            'post_mime_type' =>'application/pdf, image/jpeg, image/gif, image/jpg, image/png'
    );

$tmp = $post;
// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) {
        $the_query->the_post();
              //some code for showing result etc...
            }
    }
    $post = $tmp;
    wp_reset_postdata();

I have narrowed it down to this 'post_status' => 'any' If I change post status to something else, like: post, page, custom etc...

not any or inherit..

I get my wp editors back but dont get any result from the query... I'm a missing something here?

Was it helpful?

Solution

Found a fix! Changed WP_Query to query_posts() if someone else faces the same problem...

$args = array(
            'post_type' => 'attachment',
            'post_status' => 'inherit',
            'posts_per_page' => -1,
            'post_mime_type' =>'application/pdf, image/jpeg, image/gif, image/jpg, image/png'
    );

    $tmp = $post;
    // The Query
    $the_query2 = query_posts( $args );
    if ( $the_query2 ) {
        echo '<select class="bw_selector" name="bw_vendor_material">';
        echo '<option value="">Choose attachment:</option>';
        // The Loop
        foreach ($the_query2 as $key => $value) {
        //print_r($value->ID);
            echo '<option value="'.$value->ID.'">' . $value->post_mime_type .': '. get_the_title($value->ID) . '</option>';
        }
        echo '</select>';
        echo '<br/>';
    }
    else {
        echo "No posts found";
    }
    // Restore original Post Data
    wp_reset_query();
    $post = $tmp;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top