本文整理汇总了PHP中WP_Query::get_total方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::get_total方法的具体用法?PHP WP_Query::get_total怎么用?PHP WP_Query::get_total使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::get_total方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pmxe_wp_ajax_wpallexport
/**
* AJAX action export processing
*/
function pmxe_wp_ajax_wpallexport()
{
if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
exit(__('Security check', 'wp_all_export_plugin'));
}
if (!current_user_can(PMXE_Plugin::$capabilities)) {
exit(__('Security check', 'wp_all_export_plugin'));
}
$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;
}
$wp_uploads = wp_upload_dir();
$export = new PMXE_Export_Record();
$export->getById($export_id);
if ($export->isEmpty()) {
exit(__('Export is not defined.', 'wp_all_export_plugin'));
}
$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
wp_reset_postdata();
XmlExportEngine::$exportOptions = $exportOptions;
XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export'];
XmlExportEngine::$exportID = $export_id;
XmlExportEngine::$exportRecord = $export;
$errors = new WP_Error();
$engine = new XmlExportEngine($exportOptions, $errors);
$posts_per_page = $exportOptions['records_per_iteration'];
if ('advanced' == $exportOptions['export_type']) {
if (XmlExportEngine::$is_user_export) {
exit(json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Users', 'wp_all_export_plugin'))));
} elseif (XmlExportEngine::$is_comment_export) {
exit(json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Comments', 'wp_all_export_plugin'))));
} else {
remove_all_actions('parse_query');
remove_all_actions('pre_get_posts');
remove_all_filters('posts_clauses');
add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
$exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));');
remove_filter('posts_where', 'wp_all_export_posts_where');
remove_filter('posts_join', 'wp_all_export_posts_join');
}
} else {
XmlExportEngine::$post_types = $exportOptions['cpt'];
// $is_products_export = ($exportOptions['cpt'] == 'product' and class_exists('WooCommerce'));
if (in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt'])) {
exit(json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Users', 'wp_all_export_plugin'))));
} elseif (in_array('comments', $exportOptions['cpt'])) {
exit(json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Comments', 'wp_all_export_plugin'))));
} else {
remove_all_actions('parse_query');
remove_all_actions('pre_get_posts');
remove_all_filters('posts_clauses');
add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
$exportQuery = new WP_Query(array('post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $export->exported, 'posts_per_page' => $posts_per_page));
remove_filter('posts_where', 'wp_all_export_posts_where');
remove_filter('posts_join', 'wp_all_export_posts_join');
}
}
XmlExportEngine::$exportQuery = $exportQuery;
$engine->init_additional_data();
// get total founded records
if (XmlExportEngine::$is_comment_export) {
} else {
$foundPosts = !XmlExportEngine::$is_user_export ? $exportQuery->found_posts : $exportQuery->get_total();
$postCount = !XmlExportEngine::$is_user_export ? $exportQuery->post_count : count($exportQuery->get_results());
}
// [ \get total founded records ]
if (!$export->exported) {
$attachment_list = $export->options['attachment_list'];
if (!empty($attachment_list)) {
foreach ($attachment_list as $attachment) {
if (!is_numeric($attachment)) {
@unlink($attachment);
}
}
}
$exportOptions['attachment_list'] = array();
$export->set(array('options' => $exportOptions))->save();
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
if ($is_secure_import and !empty($exportOptions['filepath'])) {
$exportOptions['filepath'] = '';
}
PMXE_Plugin::$session->set('count', $foundPosts);
PMXE_Plugin::$session->save_data();
}
// if posts still exists then export them
if ($postCount) {
XmlCsvExport::export();
$export->set(array('exported' => $export->exported + $postCount, 'last_activity' => date('Y-m-d H:i:s')))->save();
}
if ($posts_per_page != -1 and $postCount) {
wp_send_json(array('export_id' => $export->id, 'queue_export' => false, 'exported' => $export->exported, 'percentage' => ceil($export->exported / $foundPosts * 100), 'done' => false, 'records_per_request' => $exportOptions['records_per_iteration']));
} else {
//.........这里部分代码省略.........
示例2: pmxe_wp_ajax_wpallexport
/**
* AJAX action export processing
*/
function pmxe_wp_ajax_wpallexport()
{
if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
exit(__('Security check', 'wp_all_export_plugin'));
}
if (!current_user_can('manage_options')) {
exit(__('Security check', 'wp_all_export_plugin'));
}
$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;
}
$wp_uploads = wp_upload_dir();
$export = new PMXE_Export_Record();
$export->getById($export_id);
if ($export->isEmpty()) {
exit(__('Export is not defined.', 'wp_all_export_plugin'));
}
$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
wp_reset_postdata();
XmlExportEngine::$exportOptions = $exportOptions;
XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
XmlExportEngine::$exportID = $export_id;
$posts_per_page = $exportOptions['records_per_iteration'];
if ('advanced' == $exportOptions['export_type']) {
if (XmlExportEngine::$is_user_export) {
exit(json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))));
} else {
$exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));');
}
} else {
XmlExportEngine::$post_types = $exportOptions['cpt'];
if (!in_array('users', $exportOptions['cpt'])) {
$exportQuery = new WP_Query(array('post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $export->exported, 'posts_per_page' => $posts_per_page));
} else {
exit(json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin'))));
}
}
XmlExportEngine::$exportQuery = $exportQuery;
$foundPosts = !XmlExportEngine::$is_user_export ? $exportQuery->found_posts : $exportQuery->get_total();
$postCount = !XmlExportEngine::$is_user_export ? $exportQuery->post_count : count($exportQuery->get_results());
if (!$export->exported) {
$attachment_list = $export->options['attachment_list'];
if (!empty($attachment_list)) {
foreach ($attachment_list as $attachment) {
if (!is_numeric($attachment)) {
@unlink($attachment);
}
}
}
$exportOptions['attachment_list'] = array();
$export->set(array('options' => $exportOptions))->save();
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
if ($is_secure_import and !empty($exportOptions['filepath'])) {
// if 'Create a new file each time export is run' disabled remove all previously generated source files
// if ( ! $exportOptions['creata_a_new_export_file'] or ! $export->iteration ){
// wp_all_export_remove_source(wp_all_export_get_absolute_path($exportOptions['filepath']));
// }
$exportOptions['filepath'] = '';
}
PMXE_Plugin::$session->set('count', $foundPosts);
PMXE_Plugin::$session->save_data();
}
// if posts still exists then export them
if ($postCount) {
switch ($exportOptions['export_to']) {
case 'xml':
pmxe_export_xml($exportQuery, $exportOptions);
break;
case 'csv':
pmxe_export_csv($exportQuery, $exportOptions);
break;
default:
# code...
break;
}
wp_reset_postdata();
}
if ($postCount) {
$export->set(array('exported' => $export->exported + $postCount))->save();
}
if ($posts_per_page != -1 and $postCount) {
wp_send_json(array('exported' => $export->exported, 'percentage' => ceil($export->exported / $foundPosts * 100), 'done' => false, 'records_per_request' => $exportOptions['records_per_iteration']));
} else {
wp_reset_postdata();
if (file_exists(PMXE_Plugin::$session->file)) {
if ($exportOptions['export_to'] == 'xml') {
file_put_contents(PMXE_Plugin::$session->file, '</' . $exportOptions['main_xml_tag'] . '>', FILE_APPEND);
}
$is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
if (!$is_secure_import) {
if (!$export->isEmpty()) {
$wp_filetype = wp_check_filetype(basename(PMXE_Plugin::$session->file), null);
$attachment_data = array('guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path(PMXE_Plugin::$session->file), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename(PMXE_Plugin::$session->file)), 'post_content' => '', 'post_status' => 'inherit');
if (empty($export->attch_id)) {
$attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file);
//.........这里部分代码省略.........