Performance of WordPress Plugin is currently very bad and needs to be improved I have written the following Plugin, which adds fields to the Media/Attachment Entries and returns all information in one Shortcode. This solution works, however, is pretty slow the more entries available.

I know that the problem lies in the while loop. The 20000 simply is a high number in order for all posts to be searched through.
However, I included the entire code in order to see what I'm trying to achieve:


defined( 'ABSPATH' ) or die( 'Are you ok?' );
/** ----- ADD FIELDS IN MEDIA LIBRARY ----- **/
function additionalMediaFields( $form_fields, $post ) {
    $form_fields['copyright_author'] = array(
        'label' =&gt; '&amp;copy; Autor',
        'input' =&gt; 'text',
        'value' =&gt; get_post_meta( $post-&gt;ID, 'copyright_author', true ),            
    );
    $form_fields['copyright_description'] = array(
        'label' =&gt; '&amp;copy; Beschreibung',
        'input' =&gt; 'text',
        'value' =&gt; get_post_meta( $post-&gt;ID, 'copyright_description', true ),           
    );
    $form_fields['copyright_website'] = array(
        'label' =&gt; '&amp;copy; Website',
        'input' =&gt; 'text',
        'value' =&gt; get_post_meta( $post-&gt;ID, 'copyright_website', true ),           
    );
    return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'additionalMediaFields', 10, 2 );

function storeAdditionalMediaFields( $post, $attachment ) {
    if( isset( $attachment['copyright_author'] ) )
        update_post_meta( $post['ID'], 'copyright_author', $attachment['copyright_author'] );
    if( isset( $attachment['copyright_description'] ) )
        update_post_meta( $post['ID'], 'copyright_description', $attachment['copyright_description'] );
    if( isset( $attachment['copyright_website'] ) )
        update_post_meta( $post['ID'], 'copyright_website', $attachment['copyright_website'] );
    return $post;
}
add_filter( 'attachment_fields_to_save', 'storeAdditionalMediaFields', 10, 2 );

/** ----- SHOW THEM IN ONE SHORTCODE ----- **/
function listAllCopyrightInformation ($atts, $content = null) {

    $i = 1;
    while ( $i&lt;=20000 ) {
        $copyrightAuthor = get_post_meta($i, 'copyright_author', true );
        $copyrightDescription = get_post_meta($i, 'copyright_description', true );
        $copyrightWebsite = get_post_meta($i, 'copyright_website', true );

        if ( !empty($copyrightAuthor)) {
            if( !empty($copyrightDescription)) {
                $CopyrightEntries .= $copyrightDescription . ': ';
            }
            $CopyrightEntries .= '&amp;copy; ';
            $CopyrightEntries .= $copyrightAuthor;
            if( !empty($copyrightWebsite)) {
                $CopyrightEntries .= ' / &lt;a href="https://' . get_post_meta($i, 'copyright_website', true) . '" target="_blank"&gt;' . get_post_meta($i, 'copyright_website', true) . '&lt;/a&gt; || ';
            }
        }
        $i++;
    }
    $CopyrightReturn = substr($CopyrightEntries, 0, -8);
    return $CopyrightReturn;
}

add_shortcode("show-all-copyrights", "listAllCopyrightInformation");



Thanks in advance. I appreciate your effort!
If you don't need to worry about WordPress filters on getting post meta, you probably can just do this with a single SQL statement and iterate through the results, rather than relying on WordPress to get the values from the database, since that's 20,000 sql statements, plus the memory of caching all that data (which WordPress does behind the scenes when you get post meta for a post).