本文整理汇总了PHP中WP_Comment_Query::get_comments方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Comment_Query::get_comments方法的具体用法?PHP WP_Comment_Query::get_comments怎么用?PHP WP_Comment_Query::get_comments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Comment_Query
的用法示例。
在下文中一共展示了WP_Comment_Query::get_comments方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init(&$existing_meta_keys = array())
{
if (!self::$is_active) {
return;
}
global $wp_version;
if (version_compare($wp_version, '4.2.0', '>=')) {
$commentsQuery = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
$comments = $commentsQuery->get_comments();
} else {
$comments = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
}
if (!empty($comments)) {
foreach ($comments as $comment) {
$comment_meta = get_comment_meta($comment->comment_ID, '');
if (!empty($comment_meta)) {
foreach ($comment_meta as $record_meta_key => $record_meta_value) {
if (!in_array($record_meta_key, $existing_meta_keys)) {
$to_add = true;
foreach ($this->default_fields as $default_value) {
if ($record_meta_key == $default_value['name'] || $record_meta_key == $default_value['type']) {
$to_add = false;
break;
}
}
if ($to_add) {
foreach ($this->advanced_fields as $advanced_value) {
if ($record_meta_key == $advanced_value['name'] || $record_meta_key == $advanced_value['type']) {
$to_add = false;
break;
}
}
}
if ($to_add) {
$existing_meta_keys[] = $record_meta_key;
}
}
}
}
}
}
}
示例2: test_comment_query_object
/**
* @ticket 24826
*/
public function test_comment_query_object()
{
$comment_id = self::factory()->comment->create();
$query1 = new WP_Comment_Query();
$this->assertNull($query1->query_vars);
$this->assertEmpty($query1->comments);
$comments = $query1->query(array('status' => 'all'));
$this->assertInternalType('array', $query1->query_vars);
$this->assertNotEmpty($query1->comments);
$this->assertInternalType('array', $query1->comments);
$query2 = new WP_Comment_Query(array('status' => 'all'));
$this->assertNotEmpty($query2->query_vars);
$this->assertNotEmpty($query2->comments);
$this->assertEquals($query2->comments, $query1->get_comments());
}
示例3: pmxe_wp_ajax_export_filtering_count
function pmxe_wp_ajax_export_filtering_count()
{
if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
}
if (!current_user_can(PMXE_Plugin::$capabilities)) {
exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
}
ob_start();
$input = new PMXE_Input();
$post = $input->post('data', array());
$filter_args = array('filter_rules_hierarhy' => empty($post['filter_rules_hierarhy']) ? array() : $post['filter_rules_hierarhy'], 'product_matching_mode' => empty($post['product_matching_mode']) ? 'strict' : $post['product_matching_mode']);
$input = new PMXE_Input();
$export_id = $input->get('id', 0);
if (empty($export_id)) {
$export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0;
}
$export = new PMXE_Export_Record();
$export->getById($export_id);
if (!$export->isEmpty()) {
XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff'];
}
XmlExportEngine::$is_user_export = ('users' == $post['cpt'] or 'shop_customer' == $post['cpt']) ? true : false;
XmlExportEngine::$is_comment_export = 'comments' == $post['cpt'] ? true : false;
XmlExportEngine::$post_types = array($post['cpt']);
$filters = new XmlExportFiltering($filter_args);
$filters->parseQuery();
PMXE_Plugin::$session->set('whereclause', $filters->get('queryWhere'));
PMXE_Plugin::$session->set('joinclause', $filters->get('queryJoin'));
PMXE_Plugin::$session->save_data();
$found_records = 0;
$total_records = 0;
$cpt = array($post['cpt']);
$is_products_export = ($post['cpt'] == 'product' and class_exists('WooCommerce'));
if ($post['export_type'] == 'advanced') {
if (XmlExportEngine::$is_user_export) {
// get total users
$totalQuery = eval('return new WP_User_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'number\' => 10 ));');
if (!empty($totalQuery->results)) {
$found_records = $total_records = $totalQuery->get_total();
}
} elseif (XmlExportEngine::$is_comment_export) {
// get total comments
$totalQuery = eval('return new WP_Comment_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'number\' => 10, \'count\' => true ));');
$found_records = $total_records = $totalQuery->get_comments();
} else {
remove_all_actions('parse_query');
remove_all_actions('pre_get_posts');
ob_start();
// get custom post type records depends on filters
add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
// get total custom post type records
$totalQuery = eval('return new WP_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'posts_per_page\' => 10 ));');
if (!empty($totalQuery->found_posts)) {
$found_records = $total_records = $totalQuery->found_posts;
}
wp_reset_postdata();
remove_filter('posts_join', 'wp_all_export_posts_join');
remove_filter('posts_where', 'wp_all_export_posts_where');
ob_get_clean();
}
} else {
if ('users' == $post['cpt'] or 'shop_customer' == $post['cpt']) {
// get total users
$totalQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10));
if (!empty($totalQuery->results)) {
$found_records = $total_records = $totalQuery->get_total();
}
} elseif ('comments' == $post['cpt']) {
// get total comments
global $wp_version;
if (version_compare($wp_version, '4.2.0', '>=')) {
$totalQuery = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
$found_records = $total_records = $totalQuery->get_comments();
} else {
$found_records = $total_records = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true));
}
} else {
remove_all_actions('parse_query');
remove_all_actions('pre_get_posts');
$cpt = $is_products_export ? array('product', 'product_variation') : array($post['cpt']);
ob_start();
// get custom post type records depends on filters
add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
// get total custom post type records
$totalQuery = new WP_Query(array('post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10));
if (!empty($totalQuery->found_posts)) {
$found_records = $total_records = $totalQuery->found_posts;
}
wp_reset_postdata();
remove_filter('posts_join', 'wp_all_export_posts_join');
remove_filter('posts_where', 'wp_all_export_posts_where');
ob_end_clean();
}
}
if ($post['is_confirm_screen']) {
?>
//.........这里部分代码省略.........