Carbon-fields: Media Gallery - why the quantity of items is related to post_per_page setting ?

Created on 14 Mar 2019  路  4Comments  路  Source: htmlburger/carbon-fields

Version

  • Carbon Fields: 3.0.0
  • WordPress: 5.1.1
  • PHP: 7.3.2

Expected Behavior

Add files to Media Gallery as much as it needed

Actual Behavior

Adds all loaded files but on edit page after saving post, there are only as many elements as saved in the 'post_per_page' settings.

Steps to Reproduce the Problem

  1. Go to Settings -> Read
  2. Set "Post per page" as 2 and save
  3. Add Media Gallery field to some page
  4. Add more then 2 files to gallery (they must be diffrent items)
  5. Save
  6. Scroll to media gallery and there should be only 2 items in media gallery

Comments

I checked it in two diffrent wordpress instalations.
In fact, after saving post, items of media gallery is correctly passed to page view.
After saving post, if we do not add any more files and save it again there will be only two items, also on page view.

Most helpful comment

Hey. I fixed it this way:

add_filter( 'ajax_query_attachments_args', function ( $query ) {
  if ( isset( $query['post__in'] ) && is_array( $query['post__in'] ) ) {
    $query['posts_per_page'] = count( $query['post__in'] );
  }

  return $query;
} );

All 4 comments

It looks like the same problem what I described here - https://github.com/htmlburger/carbon-fields/issues/665

I have a problem with this too. If after adding images more than posts_per_page setting and then updating, all images will still be visible, but if I reload the page the images that are visible only as much as posts_per_page

Hey. I fixed it this way:

add_filter( 'ajax_query_attachments_args', function ( $query ) {
  if ( isset( $query['post__in'] ) && is_array( $query['post__in'] ) ) {
    $query['posts_per_page'] = count( $query['post__in'] );
  }

  return $query;
} );

This has been fixed.

Please update to the latest version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonwaldstein picture jonwaldstein  路  3Comments

proweb picture proweb  路  3Comments

kaleidoscopique picture kaleidoscopique  路  3Comments

olegburakov picture olegburakov  路  3Comments

halvardos picture halvardos  路  4Comments