Support

Account

Home Forums Bug Reports Gallery Field returns empty Array

Solved

Gallery Field returns empty Array

  • Hello,

    I’m using the last ACF Pro version and I am having problems with the Gallery field.
    It returns an empty array..

    I am trying to use it in an option page as well as in a custom post type and either way it returns the same result.

    Thanks

  • What code are you using to display the gallery field?

  • I’m using this

    $gallery = get_field('test_gallery', $post_id);
    echo '<pre>';
    	var_dump( $gallery );
    echo '</pre>';

    and this for the one in the option page:

    $gallery_option = get_field('test_gallery_option', 'option');
    echo '<pre>';
    	var_dump( $gallery_option );
    echo '</pre>';

    In both cases the result is the following:
    array(0) {
    }

    I tired recreating another gallery field and it is not working. I have other field types that work without any problem.

    Thank you

  • I just checked my theme and this function is breaking the gallery functionality

    add_action('pre_get_posts','allow_pending_posts_wpse_103938');
    function allow_pending_posts_wpse_103938($qry) {
    	if (!is_admin() && current_user_can('upload_files')) {
    		$qry->set('post_status', array('publish','pending','draft'));
    	}
    }

    It basically adds post that are pending to the post archive.
    Does anyone now why it is breaking the ACF gallery?

    Thanks

  • Your filter is basically altering every front end query for all logged in users that can upload files. You need to be more specific about what queries to alter.

    This will get you started

    
    add_action('pre_get_posts','allow_pending_posts_wpse_103938');
    function allow_pending_posts_wpse_103938($qry) {
    	if (!is_admin() && current_user_can('upload_files') &&
                $qry->is_main_query()) {
    		$qry->set('post_status', array('publish','pending','draft'));
    	}
    }
    
  • Thank you for your help.

    It now makes sense.

    😀

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

The topic ‘Gallery Field returns empty Array’ is closed to new replies.