需要一些指导。我在Wordpress中建立了一个排球俱乐部网站([http://goo.gl/2Y0j10][1]),我们已经从我在Google表格/电子表格中捕获的父母那里征集了玩家个人资料数据,保存为.csv然后导入到'个人资料表。 http://dev.tavhouston.com/profile-db-table.jpg
我正在向播放器模板文件添加一些代码,该文件将根据WP post-id的匹配在html表中显示数据。我确定了所有玩家的post-id并将它们包含在“profiles”表的第一列中,称为“post_id”,并将其设置为Primary。因此,如果您打开一个名为postid-1566的播放器页面,则应显示post_id为1566的“profiles”中的行。
由于SELECT *查询,我现在得到了所有人的个人资料数据。我正在尝试将查询的语法更改为DISTINCT,以便查找配置文件表中与您所在的播放器页面具有相同post-id号的特定行。
<?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]' );
}
?>
不确定我是否接近这个最好的方式,但觉得我很接近。我认为解决方案在这个例子中的某处,但我无法让它工作。
$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'
我也无法执行“content_protector”短代码的结束标记。我可以使用do_shortcode从顶部开始,但是到那个结尾的所有内容都需要在[/ content_protector]内部,并且它不能将该行的后半部分添加到底部。有什么建议?有没有办法在短代码之间嵌套所有内容?
非常感谢任何建议!
答案 0 :(得分:0)
你做错了(核心PHP),首先你应该使用WordPress语法。 Google用于创建自定义帖子类型,并尝试为玩家创建自定义帖子类型。然后尝试编写一个脚本,使用WordPress代码插入所有播放器。请参阅以下链接 https://codex.wordpress.org/Function_Reference/wp_insert_post并且您可以使用代码创建自定义帖子类型,也可以尝试使用此插件https://wordpress.org/plugins/custom-post-type-ui/