WordPress.org

Forums

Attachments
[resolved] Array of all fields? (2 posts)

  1. Dannyqa1
    Inactive
    Posted 2 years ago #

    Hi,
    I understand that I can query attachment fields with:

    ´
    $attachments->field( 'XXX' );
    ´
    however it's a bit annoying that I need to do this with all fields. Is there a function or code snippet which allows me to store all fields in an array - eg something like:

    $fields = $attachments->get_fields();
    $field_results = array();
    
    foreach($fields as $field)
    {
    $field_results[] = $attachments->field( $field );
    }

    Thanks,
    Danny

    http://wordpress.org/extend/plugins/attachments/

  2. Jonathan Christopher
    Member
    Plugin Author

    Posted 2 years ago #

    Yes, all of the fields are returned with the original call to get(). Check out the first code snippet here under 'Pulling Attachments to your Theme' (the one with print_r())

    https://github.com/jchristopher/attachments#pulling-attachments-to-your-theme

    The field data is all returned in that result, it's a matter of snagging the return data via something like:

    while( $attachment = $attachments->get() );

    where $attachment now has the Media ID and field data you're after.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Attachments
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.