特定表

时间:2017-07-31 05:08:24

标签: post count

我正在尝试计算特定表的用户帖子。我引用了以下代码:https://codex.wordpress.org/Function_Reference/count_user_posts 但我一直为我的用户数输出零值。我的功能是

function count_user_posts_ship_to_you( $userid, $post_type = 'post', $public_only = false ) {
global $wpdb;
$NumPosts = $wpdb->get_var( "SELECT COUNT(*) FROM `ship_to_us` WHERE `user_id` = $userid" );
return $NumPosts; }

输入到我的表中的流程部分在下面引用:

$x_fields = 'ip, NumPosts';
$x_values = f_getIP() . "', '" . count_user_posts_ship_to_you($_POST['user_id']);

/*Check to see if the table exists and if it doesn't create it.*/
if ( !f_tableExists($table, DB_NAME) ) {
    $sql = "CREATE TABLE $table (
        ID int NOT NULL AUTO_INCREMENT,
        PRIMARY KEY(ID),
        ip int NOT NULL,
        NumPosts int NOT NULL
    )";
/*Insert out values into the database.*/
$sql="INSERT INTO $table ($x_fields) VALUES ('$x_values')";

我也尝试过这个问题的其他类似帖子的其他解决方案,但没有帮助我解决问题。任何帮助将不胜感激!

0 个答案:

没有答案