WordPress.org

Forums

Radio Station
DJ / Show info page.. A little help? (3 posts)

  1. Grant2013
    Member
    Posted 1 year ago #

    Hey guys,

    This is really a Modification question, not an issue. I hope i'm posting this is the right place.

    I'm trying to set up a template to display dj / show info for the currently logged in user.

    It will basically be a page that only shows up when a DJ is logged into the system and it will display all of their user/dj info as well as the shows that they are associated with including schedule, featured image etc.

    I'm calling the current user like this :

    <?php global $current_user;
          get_currentuserinfo();
    
          echo 'Username : ' . $current_user->user_login . "<br />";
          echo 'Email : ' . $current_user->user_email . "<br />";
          echo 'DJ Name : ' . $current_user->display_name . "<br />";
    ?>

    Which works as expected, but I can't figure out how to tie the current user to their show data?

    Any help would be greatly appreciated.

    Many thanks :)

    https://wordpress.org/plugins/radio-station/

  2. Nikki Blight
    Member
    Plugin Author

    Posted 1 year ago #

    You would need to query the wp_postmeta table for information, since it's actually tied to a show (which is a post type), not to a user.

    You'd be looking for a records with a meta_key value of "show_user_list". The meta_value field will be a serialized array of user id numbers, which you would then have to unserialize and check for the specific user ID you're looking for.

    So in functions.php, add something like:

    function get_user_shows($current_user) {
    	$show_user_lists = $wpdb->get_results("SELECT pm.meta_value, pm.post_id FROM {$wpdb->postmeta} pm WHERE pm.meta_key = 'show_user_list'");
    
    	//check each list for the current user
    	foreach($show_user_lists as $list) {
    
    		$list->meta_value = unserialize($list->meta_value);
    		//if a list has no users, unserialize() will return false instead of an empty array... fix that to prevent errors in the foreach loop.
    		if(!is_array($list->meta_value)) {
    			$list->meta_value = array();
    		}
    
    		//only include shows the user is assigned to
    		$shows = array();
    		foreach($list->meta_value as $user_id) {
    			if($current_user->ID == $user_id) {
    				$shows[] = $list->post_id;
    			}
    		}
    	}
    
    	return $shows;
    }

    Then in your theme you can use the show ids to pull the information for each show:

    $shows = get_user_shows($current_user);
    foreach($shows as $show) {
    	echo get_the_title($show);
    }
  3. Grant2013
    Member
    Posted 1 year ago #

    Thanks Nikki ;)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Radio Station
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.