I've built a volleyball club site in Wordpress and we've solicited player profile data from parents that I'm capturing in a Google form/spreadsheet, saving as a .csv then importing into a 'profiles' table.
I'm adding some code to the player template file that will display the data in an html table, based on a match of the WP post-id. I determined all the player's post-ids and included them in the first column of the "profiles" table, called "post_id", and set it as Primary. So if you open a player page with postid-1566 for example, the row in 'profiles' with a post_id of 1566 should be displayed.
What I've got now pulls up everyone's profile data because of the SELECT * query. I'm trying to change the syntax of the query to DISTINCT so it looks for the specific row in the profile table that has the same post-id number as the player page you're on.
<?php
global $wpdb;
// $result = $wpdb->get_results( $wpdb->prepare ( "SELECT DISTINCT $wpdb->posts.ID FROM $wpdb->profiles" ) );
$result = $wpdb->get_results( $wpdb->prepare ( "SELECT * FROM profiles" ) );
foreach ( $result as $print ) {
echo '<h6>Playing Experience </h6><p>' . $print->PlayingExperience.'</p>';
echo '<h6>Previous Clubs </h6><p>' . $print->PreviousClubs.'</p>';
echo '<h6>Athletic Awards & Accolades</h6><p>' . $print->AwardsAccolades.'</p>';
echo '<h6>Fondest Volleyball Memory</h6><p>' . $print->FondestMemory.'</p>';
echo '<h6>Best Finish</h6><p>' . $print->BestFinish.'</p>';
echo '<h6>Online Video</h6><p>' . $print->OnlineVideo.'</p>';
echo '<h3>Profile Details</h3>';
// echo '[content_protector password="xxxxxxx" cookie_expires="0" identifier="xxx"]';
// echo '[content_protector password="xxxxxxx" cookie_expires="0" identifier="xxx"]';
// In case there is opening and closing shortcode.
// echo do_shortcode( '[content_protector password="xxxxxxx" cookie_expires="0" identifier="xxx"] Private Info [/content_protector]' );
echo do_shortcode( '[content_protector password="xxxxxxx" cookie_expires="0" identifier="xxx"]' );
echo '<h2>' . $print->FirstName.' ' . $print->LastName.' </h2>';
echo '<table class="profile center">';
echo '<tr><td>Team </td><td>' . $print->Team.'</td></tr>';
echo '<tr><td>First Name </td><td>' . $print->FirstName.'</td></tr>';
echo '<tr><td>Nickname </td><td>' . $print->Nickname.'</td></tr>';
echo '<tr><td>Middle Name </td><td>' . $print->MiddleName.'</td></tr>';
echo '<tr><td>Last Name </td><td>' . $print->LastName.'</td></tr>';
echo '<tr><td>Height </td><td>' . $print->Height.'</td></tr>';
echo '<tr><td>Position </td><td>' . $print->Position.'</td></tr>';
echo '<tr><td>Birthday </td><td>' . $print->Birthday.'</td></tr>';
echo '<tr><td>School </td><td>' . $print->School.'</td></tr>';
echo '<tr><td>Grade </td><td>' . $print->Grade.'</td></tr>';
echo '<tr><td>Class </td><td>' . $print->Class.'</td></tr>';
echo '<tr><td>Commitment </td><td>' . $print->Commitment.'</td></tr>';
echo '<tr><td>Standing Reach </td><td>' . $print->Reach.'</td></tr>';
echo '<tr><td>Block Touch </td><td>' . $print->Block.'</td></tr>';
echo '<tr><td>Approach Jump </td><td>' . $print->Approach.'</td></tr>';
echo '<tr><td>GPA (Unweighted) </td><td>' . $print->GPA_Unweighted.'</td></tr>';
echo '<tr><td>GPA (Weighted) </td><td>' . $print->GPA_Weighted.'</td></tr>';
echo '<tr><td>Class Rank </td><td>' . $print->ClassRank.'</td></tr>';
echo '<tr><td>ACT Scores </td><td>' . $print->ACT_Score.'</td></tr>';
echo '<tr><td>SAT Scores </td><td>' . $print->SAT_Score.'</td></tr>';
echo '<tr><td>Parents / Guardians </td><td>' . $print->Parents.'</td></tr>';
echo '<tr><td>Parent 1 Email </td><td>' . $print->ParentEmail1.'</td></tr>';
echo '<tr><td>Parent 2 Email </td><td>' . $print->ParentEmail2.'</td></tr>';
echo '<tr><td>Address </td><td>' . $print->Address.'</td></tr>';
echo '<tr><td>City, State, Zip </td><td>' . $print->City.', ' . $print->State.', ' . $print->Zip.'</td></tr>';
echo '<tr><td>Your Cell # </td><td>' . $print->YourCell.'</td></tr>';
echo '<tr><td>Parent 1 Cell # </td><td>' . $print->ParentCell1.'</td></tr>';
echo '<tr><td>Parent 2 Cell # </td><td>' . $print->ParentCell2.'</td></tr>';
echo '<tr><td>Home Phone </td><td>' . $print->HomePhone.'</td></tr>';
echo '<tr><td>Interest in Beach Volleyball? </td><td>' . $print->BeachInterest.'</td></tr>';
echo '<tr><td>Beach Volleyball experience? </td><td>' . $print->BeachExperience.'</td></tr>';
echo '<tr><td>Next ACT/SAT date </td><td>' . $print->NextACTSATdate.'</td></tr>';
echo '<tr><td>Favorite Subjects </td><td>' . $print->FavoriteSubjects.'</td></tr>';
echo '<tr><td>Desired Area of Study </td><td>' . $print->DesiredMajor.'</td></tr>';
echo '<tr><td>Desired Level of Play </td><td>' . $print->DesiredPlayingLevel.'</td></tr>';
echo '<tr><td>State of College Preference </td><td>' . $print->CollegePreference.'</td></tr>';
echo '<tr><td>Size of School </td><td>' . $print->SchoolSize.'</td></tr>';
echo '<tr><td>Contacting schools? </td><td>' . $print->ContactingSchools.'</td></tr>';
echo '</table>';
// echo '[/content_protector]';
echo do_shortcode( '[/content_protector]' );
}
?>
Not sure if I'm approaching this the best way, but feel I'm close. I think the solution is somewhere in this example but I can't get it to work.
$rows = $wpdb->get_col( $wpdb->prepare(
"SELECT DISTINCT $wpdb->posts.ID FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND
$wpdb->posts.post_status = 'publish' AND
$wpdb->posts.post_type = 'post'
I'm also having trouble executing the closing tag of the "content_protector" shortcode. I can get it started at the top with the do_shortcode, but everything past that to the end needs to be inside that [/content_protector] and it doesn't work adding the last half of that line to the bottom. Any suggestions? Is there a way to nest everything between the shortcode?
You're doing it the wrong way(core PHP), first of all you should use WordPress syntax. Google it for creating custom post types and try creating custom post type for players. Then try to write a script that inserts all the players using WordPress code. Refer below link for the same https://codex.wordpress.org/Function_Reference/wp_insert_post and for creating custom post type you can do it using code or you can try this plugin https://wordpress.org/plugins/custom-post-type-ui/