检查数据库中是否已经存在post_content

我需要一个函数来检查post_content在数据库中是否已经存在。

内置函数post_exists()的Wordpress通过post_title进行检查。

无论post_title如何, 我都需要按post_content进行检查。

有这样的功能存在吗?

我该如何解决?

感谢你的帮助


#1


看起来post_exists()的一个小变化应该可以工作。在你的子主题的functions.php中创建一个这样的函数, 然后使用它代替post_exists():

function post_exists_by_content($content) {
  global $wpdb;

  $post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) );

  $query = "SELECT ID FROM $wpdb->posts WHERE 1=1";
  $args = array();

  if ( !empty ( $content ) ) {
    $query .= ' AND post_content = %s';
    $args[] = $post_content;
  }

  if ( !empty ( $args ) )
    return (int) $wpdb->get_var( $wpdb->prepare($query, $args) );

  return 0;
}

来源:

https://www.srcmini02.com/64885.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_41190.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?