How do I use post date and post subsite title?

When using global site search i want the results to display the title of the post, then "post by 'author' on 'post_date' in 'subsite title'

I can get the title and post author but which variables do i use for post date and subsite title?

  • Vaughan

    hiya

    i'm not entirely sure as it doesn't seem to cater for that.

    you would probably have to use http://codex.wordpress.org/Function_Reference/get_the_date

    somewhere in the code, to grab the post date. i'm not sure of the subsite title. i've looked in the code, but i'm not entirely sure which function is used.

    i will have to ask the developer for some feedback for you.

    hope this helps.

  • Ash

    @Vaughan: Hi Vaughan, I hope you wouldn't mind if I dive into this.

    @Clayton: Hi Clayton,

    Would you please replace the

    if(!empty($phrase)) {
    ...
    ...
    ...
    }

    from line no 347 to line no 417 in global-site-search.php with the following:

    if(!empty($phrase)) {
    				$network_query_posts = network_query_posts( $parameters );
    				$i = 0;
    				//found_posts
    				if( network_have_posts() && isset($GLOBALS['network_query']->found_posts) && $GLOBALS['network_query']->found_posts > intval( $global_site_search_per_page ) ) {
    					$next = 'yes';
    					$navigation_content = $this->new_pagination( $GLOBALS['network_query'], $current_site->path . $this->global_site_search_base . '/' . urlencode($phrase) );
    				}
    
    				if ( network_have_posts() ) {
    					$content .= (isset($navigation_content)) ? $navigation_content : '';
    
    					$content .= '<div style="float:left; width:100%">';
    					$content .= '<table border="0" border="0" width="100%" bgcolor="">';
    					$content .= '<tr>';
    					$content .= '<td style="background-color:' . $global_site_search_background_color . '; border-bottom-style:solid; border-bottom-color:' . $global_site_search_border_color . '; border-bottom-width:1px; font-size:12px;" width="10%"> </td>';
    					$content .= '<td style="background-color:' . $global_site_search_background_color . '; border-bottom-style:solid; border-bottom-color:' . $global_site_search_border_color . '; border-bottom-width:1px; font-size:12px;" width="90%"><center><strong>' .  __('Posts', 'globalsitesearch') . '</strong></center></td>';
    					$content .= '</tr>';
    
    					// Search results
    
    					$avatar_default = get_option('avatar_default');
    					$tic_toc = 'toc';
    
    					while( network_have_posts()) {
    						network_the_post();
    
    						//=============================//
    						$author_id = network_get_the_author_id();
    						$the_author = get_user_by( 'id', $author_id );
    
    						if(!$the_author) {
    							$post_author_display_name = __('Unknown', 'globalsitesearch');
    						} else {
    							$post_author_display_name = $the_author->display_name;
    						}
    						$tic_toc = ($tic_toc == 'toc') ? 'tic' : 'toc';
    						$bg_color = ($tic_toc == 'tic') ? $global_site_search_alternate_background_color : $global_site_search_background_color;
    
    						//=============================//
    						$content .= '<tr>';
    							$content .= '<td style="background-color:' . $bg_color . '; padding-top:10px; text-align: center;" valign="top" width="10%"><a style="text-decoration:none;" href="' . network_get_permalink() . '">' . get_avatar( $author_id, 32, $avatar_default ) . '</a></td>';
    							$content .= '<td style="background-color:' . $bg_color . '; padding-top:10px; vertical-align: top;" width="90%" valign="top">';
    							$content .= '<strong><a style="text-decoration:none;" href="' . network_get_permalink() . '">' . network_get_the_title() . '</a></strong> - ';
    							$content .= __('Post by ', 'globalsitesearch');
    							if ( function_exists('members_directory_site_admin_options') ) {
    								$post_author_nicename = $the_author->user_nicename;
    								$content .= '<strong><a style="text-decoration:none;" href="http://' . $current_site->domain . $current_site->path . $members_directory_base . '/' . $post_author_nicename . '/">' . $post_author_display_name . '</a> </strong> ';
    							} else {
    								$content .= '<strong>' . $post_author_display_name . ': </strong> ';
    							}
    							$content .= ' on ';
    							$content .= date("d M Y", strtotime($network_query_posts[$i]->post_date));
    							$content .= ' in ';
    							$blog_details = get_blog_details($network_query_posts[$i]->BLOG_ID);
    							$content .= '<a href="'.$blog_details->siteurl.'" target="_blank">'.$blog_details->blogname.'</a>';
    							$content .= '<br>';
    							$the_content = network_get_the_content();
    							$content .= substr(strip_tags( $the_content ),0, 250) . ' (<a href="' . network_get_permalink() . '">' . __('More', 'globalsitesearch') . '</a>)';
    							$content .= '</td>';
    						$content .= '</tr>';
    						$i++;
    
    					}
    
    					$content .= '</table>';
    					$content .= '</div>';
    					$content .= (isset($navigation_content)) ? $navigation_content : '';
    				} else {
    					$content .= '<p>';
    					$content .= '<center>';
    					$content .= __('Nothing found for search term(s).', 'globalsitesearch');
    					$content .= '</center>';
    					$content .= '</p>';
    				}
    
    			}

    Let me know if it works for you. It worked for me. See screenshot.

    Note: Please keep a backup of original file, so if anything goes wrong, you can restore backed up file.

    Cheers
    Ash

  • Ash

    Hey Clayton

    I am glad it helped.

    But one thing, I strongly want to mention that, if you update this plugin, this changes will be lost. So you should take a note about the changes (what are the changes and where to edit), so that after updating the plugin you can insert again. On the other hand, you can continue using the older version but you could miss new feature then.

    Thanks for being a WPMU member.

    Cheers
    Ash