Forum Replies Created

Viewing 15 replies - 16 through 30 (of 32 total)
  • Thread Starter jwrbloom

    (@jwrbloom)

    This is getting me closer. At least now it’s not producing any blank results. However, when it’s a player’s name, it just produces that player, not the others. (I know it wouldn’t. I just fixed the blank result issue.

    Now I need the list to produce regardless of what type of tag it is.

    
    $query = "SELECT nameFirst,nameLast,feet,inches,city,school,grade FROM a_players
    			WHERE (school = '".$tag."' || CONCAT(nameFirst,' ', nameLast) = '".$tag."')
    			AND grade>='20'";
    			
    
    Thread Starter jwrbloom

    (@jwrbloom)

    Here is what it looks like when a player’s name is the tag:
    https://www.courtsideindiana.com/tag/pierce-thomas/

    No results

    Here is what it looks like when a team’s name is the tag:
    https://www.courtsideindiana.com/tag/brownsburg/

    It’s able to create the header and find four rows.

    It’s the right side where I’m producing the list.

    Thread Starter jwrbloom

    (@jwrbloom)

    I typically start PHP includes with ABSPATH.

    For this, I went ahead and put the CSS link in the theme’s designated “custom HTML” section.

    Thread Starter jwrbloom

    (@jwrbloom)

    For anyone else who comes across this problem:

    I figured it out using the ob_start and ob_get_clean functions.
    (see more on php output buffers)

    Replaced what is in the while loop above with…

    
     	ob_start();
     	
     		echo '<b>' . $row['school'] . '</b><br/>
     			<ul style="list-style-type:none;">';
     		
     		$players = $row['players'];
     		$players = explode("; ",$players);
     		
     			foreach ($players as $player) {
     				echo '<li>' . $player . '</li>';
     				
     			}
     			echo '</ul>';
     			
     	$player_list = ob_get_clean();
     	
     	return $player_list;
    	
    	}
    
    }
    add_shortcode('players', 'team_players');
    
    

    The ob_start starts the buffer.
    The ob_get_clean gets what’s in the buffer and empties for its next use.

    • This reply was modified 5 years, 3 months ago by jwrbloom.
    Thread Starter jwrbloom

    (@jwrbloom)

    @bcworkz it is working great, but I wanted to alter something.

    $row[‘players’] creates a list of 3-4 players for a given team. It’s inline. I want it produced in an unordered list. I know how to explode and sort the list, but I’m not sure who to make it work within the ‘return’.

    Echoing doesn’t work. (Is that a WordPress thing? Not fully sure why I have to return vs echo, when I see examples other functions doing that, but that’s not important right now.) I’ve tried return array, likely incorrectly.

    
    function team_players( $atts, $content ) {
       $a = shortcode_atts( array(
     	'team' => '',
     	), $atts );
         if ( empty ( $a['team'] )) {
            return 'Empty';
         }
    
     $team = $a['team'];
    
    include(ABSPATH ."resources/con.php");
     
     $query = "SELECT * FROM a_game_preview_players
     where teamID = '" . $team . "'";
     
    $results = mysqli_query($con,$query);
    echo mysqli_error($con);
    while($row = mysqli_fetch_assoc($results)) {
     
    	return '<b>' . $row['school'] . '</b><br/>'
    		. $row['players'];
    
    	}
    
    }
    add_shortcode('players', 'team_players');
    
    
    Thread Starter jwrbloom

    (@jwrbloom)

    Turns out it was a syntax issue with the shortcode

    Should be…
    [team_preview team='Carmel']
    …single quotes.

    Instead of…
    [team_preview team=“Carmel”]
    …double quotes.

    Thank you for the input!

    • This reply was modified 5 years, 3 months ago by bcworkz. Reason: expose curly quotes
    Thread Starter jwrbloom

    (@jwrbloom)

    I did try $team, but it didn’t change anything. When I coded the team name in the query, it worked, but it’s not getting the team value from the shortcode.

    Thread Starter jwrbloom

    (@jwrbloom)

    This is what I have now. I’m not sure it’s getting the team value from the shortcode

    [team_preview team=“Carmel”]

    It’s returning blank. It should have one row of data and return Test. I was able to get it to return Test before the actual query.

    
    function team_players( $atts, $content ) {
       $a = shortcode_atts( array(
     	'team' => '',
     	), $atts );
         if ( empty ( $a['team'] )) {
            return '';
         }
    
     $team = $a['team'];
    
    include(ABSPATH ."resources/con.php");
     
     $query = "SELECT * FROM a_game_preview_players
     where school = '" . $atts . "'";
     
    $results = mysqli_query($con,$query);
    echo mysqli_error($con);
    while($row = mysqli_fetch_assoc($results)) {
     
    	return 'Test';
    
    	}
    
    • This reply was modified 5 years, 3 months ago by jwrbloom.
    • This reply was modified 5 years, 3 months ago by jwrbloom.
    Thread Starter jwrbloom

    (@jwrbloom)

    Yes…that’s it @bcworkz. Thank you!

    I may have an output question when I get back to my desk and really dig in, but at least now it’s working.

    Thread Starter jwrbloom

    (@jwrbloom)

    I’m just not able to wrap my head around it. I’d like to just see how a basic shortcode produces before I get too deeply into building the query. Otherwise, I won’t know what’s working and what isn’t.

    I put [team_preview] in a post, and it just showed [team_preview].

    
    function team_players( $atts, $content ) {
    
    	return 'Hello';
    
    }
    add_shortcode(‘team_preview’, ‘team_players’);
    
    Thread Starter jwrbloom

    (@jwrbloom)

    I created a plugin, have it uploaded and activated. This is what I have, which is essentially when you put, but before digging into the query, I just wanted to see if my site is reading the function.

    It’s not.

    In a post, I put [team_preview], and it didn’t print Hello. It just printed [team_preview]. What am I missing?

    
    function team_players( $atts, $content ) {
       $a = shortcode_atts( array(
    	'team' => '',
    	), $atts );
        if ( empty ( $a['team'] )) {
           return '';
        }
    
    $team = $a['team'];
    
    	echo 'Hello';
    
    return $results;
    }
    add_shortcode(‘team_preview’, ‘team_players’);
    
    
    Thread Starter jwrbloom

    (@jwrbloom)

    
    where team = . ‘ $atts ‘ .
    

    Is that how it would be used in the query?

    FYI – I’m not using any information from wp_ tables for this query.

    • This reply was modified 5 years, 3 months ago by jwrbloom.
    • This reply was modified 5 years, 3 months ago by jwrbloom.
    Thread Starter jwrbloom

    (@jwrbloom)

    I had one a LONG time ago, but it I don’t recall it being totally reliable. It just seems like an obvious thing to have at least as option. I will definitely check those out.

    Thank you.

    Thread Starter jwrbloom

    (@jwrbloom)

    It turned out my issue was my tags are typed 2018, 2019, 2020, etc. My database has 18, 19, 20, and where on my pages, where I need to I echo ’20’ . $grade .

    I had to define the variable as $grade = ’20’ . $_GET[‘grade’];

    Thank you. I tried what you wrote a few times, going back and forth. Nothing was working. After I read your post, it told me there was something else wrong.

    Thread Starter jwrbloom

    (@jwrbloom)

    It works putting tag=> myTag as one of the args.

    Now the question is, how do I replace myTag with a $variable.

    This isn’t working…

    $args = array( "posts_per_page" => 10, "tag"=> ' . $grade .');

    • This reply was modified 7 years, 6 months ago by bcworkz. Reason: code fixed
Viewing 15 replies - 16 through 30 (of 32 total)