• Hi,

    We’ve an issue with the edit voucher page in backend ( the plugin has been hacked), and so we can not anymore attribuate any voucher to an advertiser(user role).

    Seems that the dropdown that lists posts in this page is too long and make server crash.

    So I think that we can set up this dropdown to only display posts attribuated to author that have the advertiser role. But we really can’t do this, we search search search…..

    Maybe ca anyone tell me what to add in the dropdown function for filter posts_type place and event only per user_role advertiser?????? thxxxxxxxxx

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    /**
     * Posts dropdown themes-function.php (in theme/at/lib )
     *
     * @param array $post_args
     * @param array $args
     * @return string
     */
    function dlp_posts_dropdown( $post_args = NULL, $args = NULL ) {
        $defaults = array(
            'numberposts' => -1,
            'orderby' => 'post_type',
            'post_status' => 'publish'
    //May be something to add here but I don't know what !!! we try
     // 'author_role' => implode(',',$ids),
        );
    
        $args_defaults = array(
            'name' => 'posts_dropdown',
            'id' => 'posts_dropdown',
            'selected' => 0,
            'select' => __( '- Select -', 'dlp' ),
            'show_type' => true
        );
    
        $post_args = wp_parse_args($post_args, $defaults);
        $args = wp_parse_args($args, $args_defaults);
    
        $posts = get_posts( $post_args );
        $select = sprintf( '<select name="%s" id="%s">', $args['name'], $args['id'] );
        $select .= sprintf( '<option value="-1">%s', $args['select'] );
    
        foreach ($posts as $post) {
            $type = $args['show_type'] ? ' (' . dlp_get_translated_post_type( $post->post_type ) . ')' : '';
            $select .= sprintf( '<option value="%s"%s>%s%s</option>', $post->ID, selected( $args['selected'], $post->ID, false ), $post->post_title, $type );
        }
    
        $select .= '</select>';
    
        return $select;
    }
    
    ========================================= InContent/plugins/vouchers/vouchers.php=================
    
    // this line showed all the postype event and place( before it was worked ). But we have a white screen of the death cause there are many posts
        echo '<p><label for="posts">Post</label></p>';
        echo dlp_posts_dropdown( array('post_type' => array('place', 'event'), 'orderby' => 'name', 'order' => 'ASC' ), array( 'name' => 'user_post[]' ) );
        echo dlp_posts_dropdown( array('post_type' => array('place', 'event'), 'orderby' => 'name', 'order' => 'ASC' ), array( 'name' => 'user_post[]' ) );
        echo dlp_posts_dropdown( array('post_type' => array('place', 'event'), 'orderby' => 'name', 'order' => 'ASC' ), array( 'name' => 'user_post[]' ) );

The topic ‘dropdown lists posts too long and make server crash’ is closed to new replies.