Forums

Media Tags
get_attachments_by_media_tags() twice offset fix (2 posts)

  1. alx359
    Member
    Posted 10 months ago #

    This one was tricky.

    I'm doing archive.php pagination using get_attachments_by_media_tags(). For example, let's say I'm calling it this way:

    $media_items  = get_attachments_by_media_tags('media_tags=cars&size=full&offset=10&numberposts=10);

    Let's also say the 'cars' tag has 50 assigned media attachments in the DB.

    What I expect it to happen:
    - $media_items object array to contain the references to 10 attachments, which are between 10-20th of 50 (i.e. offset of 10)

    What really happens:
    - $media_items object array contains the reference to 10 attachments, but they are between 20-30 of 50 (i.e. starts at 2x the offset)

    The offending code and reason for this below.

    media-tags\media_tags.php ~li 344

    // If the calling system doesn't want the whole list.
    
    //[alx359] offset already sliced the attachment_posts array when calling get_posts() above. No need do again.
    /*
    if (($r['offset'] > 0) || ($r['numberposts'] > 0))
    	$attachment_posts = array_slice($attachment_posts, $r['offset'], $r['numberposts']);
    */
    if ($r['numberposts'] > 0)
    	$attachment_posts = array_slice($attachment_posts, 0, $r['numberposts']);
  2. pmenard
    Member
    Posted 10 months ago #

    Thanks. That whole core function needs to be reviewed at some point. It was written way back. Thanks.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags