• Resolved cerebcortex

    (@cerebcortex)


    I am trying to echo all author posts for each user as URLs with user_id as the author id in a custom column within the User List table (User.php)… not sure what is wrong.. Thanks!

    function new_modify_user_table_send_inv( $column ) {
        $column['send_inventory'] = 'Email Inventory';
        return $column;
    }
    add_filter( 'manage_users_columns', 'new_modify_user_table_send_inv' );
    
    function new_modify_user_table_row_send_inv($custom_column, $column_name, $user_id ) {
    	if ($column_name=='send_inventory') {
    			$posts = get_posts(array('author'=>$user_id));
    			$custom_column = array();
    			if(isset($posts) && !empty($posts))
    				foreach($posts as $post){
    					$custom_column[] = "<li>".$post->post_title."</li>";
    				}
    			$custom_column = implode("\n",$custom_column);
    	}
    	return $custom_column;
    }
    add_filter( 'manage_users_custom_column', 'new_modify_user_table_row_send_inv', 10, 3 );
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    echo $custom_column;, you don’t need to return anything.

    Wouldn’t you end up with a huge table cell if the author has a lot of posts? Not that’s any of my business, no response required.

    Thread Starter cerebcortex

    (@cerebcortex)

    changed return $custom_column; to echo $custom_column but nothing shows for each row… I am just adding this to my custom functions.. the column head populates but now data is showing.

    I was just trying to display each posts as URLs in each user row 1st..

    The end goal is clicking a button on a specific user row in the column which would send an email to the user with their specific posts in the body…

    Thread Starter cerebcortex

    (@cerebcortex)

    **No row data for column is showing**

    new code:

    <?php
    function new_modify_user_table_send_inv( $column ) {
        $column['send_inventory'] = 'Email Inventory';
        return $column;
    }
    add_filter( 'manage_users_columns', 'new_modify_user_table_send_inv' );
    
    function new_modify_user_table_row_send_inv($custom_column, $column_name, $user_id ) {
    	if ($column_name=='send_inventory') {
    			$posts = get_posts(array('author' => 2));
    			$custom_column = array();
    			if(isset($posts) && !empty($posts))
    				foreach($posts as $post){
    					$custom_column[] = "<li>".$post->post_title."</li>";
    				}
    			$custom_column = implode("\n",$custom_column);
    	}
    	echo $custom_column;
    }
    add_filter( 'manage_users_custom_column', 'new_modify_user_table_row_send_inv', 10, 3 );
    Thread Starter cerebcortex

    (@cerebcortex)

    Okay I’ve gotten it to show the first post a specific user has for all user rows since I set it to ‘author’ => 2… but it only shows the first post and not the subsequent…

    <?php
    function new_modify_user_table_send_inv( $column ) {
        $column['send_inventory'] = 'Email Inventory';
        return $column;
    }
    add_filter( 'manage_users_columns', 'new_modify_user_table_send_inv' );
    
    function new_modify_user_table_row_send_inv($value='', $column_name, $user_id ) {
        if ($column_name =='send_inventory') {
    			$posts = get_posts(array('author' => 2));
    			$tmpdata = array();
    			if(isset($posts) && !empty($posts))
    				foreach($posts as $post){
    					$tmpdata = "<li>".$post->post_title."</li>";
                        return $tmpdata;
    			}
            			//return $print_array;
    		//$tmpdata = implode("\n",$tmpdata);
    
            //$custom_column = implode("\n",$custom_column);
            	//echo $custom_column;
    	}
    }
    add_filter( 'manage_users_custom_column', 'new_modify_user_table_row_send_inv', 9999, 3 );
    Thread Starter cerebcortex

    (@cerebcortex)

    SOLVED:

    <?php
    
    function new_modify_user_table_send_inv( $column ) {
        $column['send_inventory'] = 'Email Inventory';
        return $column;
    }
    add_filter( 'manage_users_columns', 'new_modify_user_table_send_inv' );
    
    function new_modify_user_table_row_send_inv($value='', $column_name, $user_id ) {
        if ($column_name =='send_inventory') {
    			$posts = get_posts(array('author' => $user_id));
    			$tmpdata = array();
    			if(isset($posts) && !empty($posts))
    				foreach($posts as $post){
    					$tmpdata[] = "<li>".$post->post_title."</li>";
    			}
    						$varnew = implode("\n",$tmpdata);
            				return $varnew;
    	}
    }
    add_filter( 'manage_users_custom_column', 'new_modify_user_table_row_send_inv', 9999, 3 );
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Trying to echo posts of author on user page’ is closed to new replies.