本文整理汇总了PHP中get_posts函数的典型用法代码示例。如果您正苦于以下问题:PHP get_posts函数的具体用法?PHP get_posts怎么用?PHP get_posts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_posts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bap_ajaxP_loop
function bap_ajaxP_loop($offset = '')
{
global $wp_query;
$paged = get_query_var('page') ? get_query_var('page') : 1;
$do_not_duplicate = array();
// OFFSET SETTING
if (!$offset == '' || !$offset == '0') {
$argshidepost = array('numberposts' => $offset, 'post_type' => 'post', 'post_status' => 'publish');
$hide_to_array = get_posts($argshidepost);
// HIDE OFFSETED POSTS
if ($hide_to_array) {
foreach ($hide_to_array as $post) {
$do_not_duplicate[] = $post->ID;
}
}
}
$argsmain = array('post_type' => 'post', 'post_status' => 'publish', 'paged' => $paged, 'order' => 'DESC', 'post__not_in' => $do_not_duplicate);
$wp_query = new WP_Query($argsmain);
if ($wp_query->have_posts()) {
echo '<section id="' . bap_get_option_text('bap_loopContainer') . '">';
while ($wp_query->have_posts()) {
$wp_query->the_post();
get_template_part('partials/listitem');
}
echo '</section>';
}
wp_reset_postdata();
}
示例2: suggest_similar_questions
/**
* Show similar questions when asking a question.
*
* @since 2.0.1
*/
public function suggest_similar_questions()
{
if (empty($_POST['value']) || !ap_verify_default_nonce() && !current_user_can('manage_options')) {
wp_die('false');
}
$keyword = sanitize_text_field(wp_unslash($_POST['value']));
$is_admin = (bool) $_POST['is_admin'];
$questions = get_posts(array('post_type' => 'question', 'showposts' => 10, 's' => $keyword));
if ($questions) {
$items = '<div class="ap-similar-questions-head">';
$items .= '<h3>' . ap_icon('check', true) . sprintf(__('%d similar questions found', 'anspress-question-answer'), count($questions)) . '</h3>';
$items .= '<p>' . __('We\'ve found similar questions that have already been asked, click to read them.', 'anspress-question-answer') . '</p>';
$items .= '</div>';
$items .= '<div class="ap-similar-questions">';
foreach ($questions as $p) {
$count = ap_count_answer_meta($p->ID);
$p->post_title = ap_highlight_words($p->post_title, $keyword);
if ($is_admin) {
$items .= '<div class="ap-q-suggestion-item clearfix"><a class="select-question-button button button-primary button-small" href="' . add_query_arg(array('post_type' => 'answer', 'post_parent' => $p->ID), admin_url('post-new.php')) . '">' . __('Select', 'anspress-question-answer') . '</a><span class="question-title">' . $p->post_title . '</span><span class="acount">' . sprintf(_n('1 Answer', '%d Answers', $count, 'anspress-question-answer'), $count) . '</span></div>';
} else {
$items .= '<a class="ap-sqitem clearfix" target="_blank" href="' . get_permalink($p->ID) . '"><span class="acount">' . sprintf(_n('1 Answer', '%d Answers', $count, 'anspress-question-answer'), $count) . '</span><span class="ap-title">' . $p->post_title . '</span></a>';
}
}
$items .= '</div>';
$result = array('status' => true, 'html' => $items);
} else {
$result = array('status' => false, 'message' => __('No related questions found', 'anspress-question-answer'));
}
$this->send($result);
}
示例3: widget
/**
* Displays the output
*
* @param array $args
* @param array $instance
* @since Achievements (3.3)
*/
public function widget($args, $instance)
{
$settings = $this->parse_settings($instance);
$settings['post_id'] = absint(apply_filters('dpa_featured_achievement_post_id', $settings['post_id'], $instance, $this->id_base));
// Get the specified achievement
$achievement = get_posts(array('no_found_rows' => true, 'numberposts' => 1, 'p' => $settings['post_id'], 'post_status' => 'publish', 'post_type' => dpa_get_achievement_post_type(), 'suppress_filters' => false));
// Bail if it doesn't exist
if (empty($achievement)) {
return;
}
$achievement = array_shift($achievement);
$title = dpa_get_achievement_title($achievement->ID);
echo $args['before_widget'];
echo $args['before_title'] . $title . $args['after_title'];
if (has_post_thumbnail($achievement->ID)) {
?>
<a href="<?php
dpa_achievement_permalink($achievement->ID);
?>
"><?php
echo get_the_post_thumbnail($achievement->ID, 'thumbnail', array('alt' => $title));
?>
</a>
<?php
}
dpa_achievement_excerpt($settings['post_id']);
echo $args['after_widget'];
}
示例4: oxy_filter_import_menu_item
function oxy_filter_import_menu_item($new_menu_item, $menu_item, $one_click)
{
switch ($menu_item['type']) {
case 'post_type':
case 'taxonomy':
switch ($menu_item['object']) {
case 'oxy_mega_menu':
$mega_menu = get_page_by_title('Mega Menu', 'OBJECT', 'oxy_mega_menu');
$new_menu_item['menu-item-object-id'] = $mega_menu->ID;
break;
case 'oxy_mega_columns':
$columns = get_posts(array('post_type' => 'oxy_mega_columns'));
foreach ($columns as $column) {
if ($column->post_content === $menu_item['post_content']) {
$new_menu_item['menu-item-object-id'] = $column->ID;
}
}
break;
default:
$new_id = $one_click->lookup_map($menu_item['object'], $menu_item['object_id']);
if ($new_id !== false) {
$new_menu_item['menu-item-object-id'] = $new_id;
}
break;
}
break;
case 'custom':
default:
// do nothing
break;
}
return $new_menu_item;
}
示例5: callback
function callback($path = '', $blog_id = 0)
{
$blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
if (is_wp_error($blog_id)) {
return $blog_id;
}
//upload_files can probably be used for other endpoints but we want contributors to be able to use media too
if (!current_user_can('edit_posts')) {
return new WP_Error('unauthorized', 'User cannot view media', 403);
}
$args = $this->query_args();
if ($args['number'] < 1) {
$args['number'] = 20;
} elseif (100 < $args['number']) {
return new WP_Error('invalid_number', 'The NUMBER parameter must be less than or equal to 100.', 400);
}
$media = get_posts(array('post_type' => 'attachment', 'post_parent' => $args['parent_id'], 'offset' => $args['offset'], 'numberposts' => $args['number'], 'post_mime_type' => $args['mime_type']));
$response = array();
foreach ($media as $item) {
$response[] = $this->get_media_item($item->ID);
}
$_num = (array) wp_count_attachments();
$_total_media = array_sum($_num) - $_num['trash'];
$return = array('found' => $_total_media, 'media' => $response);
return $return;
}
示例6: woo_widget_tabs_latest
function woo_widget_tabs_latest($posts = 5, $size = 45)
{
global $post;
$latest = get_posts(array('suppress_filters' => false, 'ignore_sticky_posts' => 1, 'orderby' => 'post_date', 'order' => 'desc', 'numberposts' => $posts));
foreach ($latest as $post) {
setup_postdata($post);
?>
<li>
<?php
if ($size != 0) {
woo_image('height=' . $size . '&width=' . $size . '&class=thumbnail&single=true');
}
?>
<a title="<?php
the_title_attribute();
?>
" href="<?php
the_permalink();
?>
"><?php
the_title();
?>
</a>
<span class="meta"><?php
the_time(get_option('date_format'));
?>
</span>
<div class="fix"></div>
</li>
<?php
}
wp_reset_postdata();
}
示例7: property_post_list
function property_post_list()
{
$propid_array = array();
$args = array('numberposts' => -1, 'meta_key' => 'property_id');
$posts_array = get_posts($args);
if (count($posts_array) > 0) {
foreach ($posts_array as $p) {
//print_r($posts_array);exit();
$propid = get_post_custom_values('property_id', $p->ID);
if (!empty($propid)) {
$prop_array[$p->ID] = $propid;
}
}
}
?>
<script>
var prop_post_array = new Array();
<?php
foreach ($prop_array as $po => $pr) {
?>
prop_post_array[<?php
echo $pr[0];
?>
] = <?php
echo $po;
?>
;
<?php
}
?>
</script>
<?php
}
示例8: output
/**
* Output the metabox
*/
public static function output($post)
{
$metrics = get_post_meta($post->ID, 'sp_metrics', true);
$args = array('post_type' => 'sp_metric', 'numberposts' => -1, 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC');
$vars = get_posts($args);
if ($vars) {
foreach ($vars as $var) {
?>
<p><strong><?php
echo $var->post_title;
?>
</strong></p>
<p><input type="text" name="sp_metrics[<?php
echo $var->post_name;
?>
]" value="<?php
echo esc_attr(sp_array_value($metrics, $var->post_name, ''));
?>
" /></p>
<?php
}
} else {
sp_post_adder('sp_metric', __('Add New', 'sportspress'));
}
}
示例9: ctc_get_locations
/**
* Get locations
*
* This can optionally be used by the template.
* $this->instance is sanitized before being made available here.
*
* @since 0.9
* @return array Posts for widget template
*/
function ctc_get_locations($instance)
{
// Get posts
$posts = get_posts(array('post_type' => 'ctc_location', 'orderby' => $instance['orderby'], 'order' => $instance['order'], 'numberposts' => $instance['limit'], 'suppress_filters' => false));
// Return filtered
return apply_filters('ctc_locations_widget_get_posts', $posts);
}
示例10: add_post_details
private function add_post_details()
{
$post_ids = array();
$posts = array();
foreach ($this->response['comments'] as $id => $comment) {
$post_ids[$comment['comment_post_ID']] = true;
}
$post_ids = array_keys($post_ids);
if (!empty($post_ids)) {
$posts = get_posts(array('post__in' => $post_ids));
}
foreach ($posts as $post) {
$id = $post->ID;
$post = (array) $post;
unset($post['ID']);
unset($post['post_content']);
unset($post['post_excerpt']);
unset($post['post_password']);
unset($post['post_modified']);
unset($post['post_modified_gmt']);
unset($post['to_ping']);
unset($post['pinged']);
unset($post['post_content_filtered']);
unset($post['menu_order']);
unset($post['filter']);
$this->response['posts'][$id] = $post;
}
}
示例11: gmb_show_upgrade_notices
/**
* Display Upgrade Notices.
*
* @since 2.0
* @return void
*/
function gmb_show_upgrade_notices()
{
// Don't show notices on the upgrades page.
if (isset($_GET['page']) && $_GET['page'] == 'gmb-upgrades') {
return;
}
//Check to see if we have any posts.
$gmb_posts = get_posts(array('post_type' => 'google_maps', 'posts_per_page' => 10));
if (empty($gmb_posts)) {
update_option('gmb_refid_upgraded', 'upgraded');
//mark as updated.
return;
//Don't run if there's no posts!
}
$gmb_version = get_option('gmb_version');
if (!$gmb_version) {
// 2.0 is the first version to use this option so we must add it.
$gmb_version = '2.0';
}
update_option('gmb_version', GMB_VERSION);
$gmb_version = preg_replace('/[^0-9.].*/', '', $gmb_version);
if (version_compare($gmb_version, '2.0', '<=') && !get_option('gmb_refid_upgraded')) {
printf('<div class="updated"><p><strong>' . __('Maps Builder Update Required', 'google-maps-builder') . ':</strong> ' . esc_html__('Google has updated their Maps API to use the new Google Places ID rather than previous Reference ID. The old method will soon be deprecated and eventually go offline. We are being proactive and would like to update your maps to use the new Places ID. Once you upgrade, your maps should work just fine but remember to make a backup prior to upgrading. If you choose not to upgrade Google will eventually take the old reference ID offline (no date has been given). Please contact WordImpress support via our website if you have any further questions or issues. %sClick here to upgrade your maps to use the new Places ID%s', 'google-maps-builder') . '</p></div>', '<br><a href="' . esc_url(admin_url('options.php?page=gmb-upgrades')) . '" class="button button-primary" style="margin-top:10px;">', '</a>');
} elseif (version_compare($gmb_version, '2.1', '<=') && !gmb_has_upgrade_completed('gmb_markers_upgraded')) {
printf('<div class="updated"><p><strong>' . __('Maps Builder Update Required', 'google-maps-builder') . ':</strong> ' . esc_html__('An upgrade is required to update your Google maps with the latest plugin version. Please perform a site backup and then upgrade. %sClick here to upgrade your maps%s', 'google-maps-builder') . '</p></div>', '<br><a href="' . esc_url(admin_url('options.php?page=gmb-upgrades')) . '" class="button button-primary" style="margin-top:10px;">', '</a>');
}
}
示例12: legacy_upgrade
/**
* Performs a legacy upgrade for sliders from v1 to v2.
*
* @since 1.0.0
*/
public function legacy_upgrade()
{
// If the option exists for upgrading, do nothing.
$upgrade = get_option('soliloquy_upgrade');
if ($upgrade) {
return;
}
// If the option exists for already checking for sliders from previous versions, bail.
$has_sliders = get_option('soliloquy_lite_upgrade');
if ($has_sliders) {
return;
}
// If we have no sliders, only run this check once. Set option to prevent again.
$sliders = get_posts(array('post_type' => 'soliloquy', 'posts_per_page' => -1));
if (!$sliders) {
update_option('soliloquy_lite_upgrade', true);
return;
}
?>
<div class="error">
<p><?php
printf(__('Soliloquy Lite is now rocking v2! <strong>You need to upgrade your legacy v1 sliders to v2.</strong> <a href="%s">Click here to begin the upgrade process.</a>', 'soliloquy'), add_query_arg('page', 'soliloquy-lite-settings', admin_url('edit.php?post_type=soliloquy')));
?>
</p>
</div>
<?php
}
示例13: sys_recent_posts
function sys_recent_posts($atts, $content = null)
{
extract(shortcode_atts(array('limit' => '2', 'description' => '40', 'cat_id' => '23', 'thumb' => 'true', 'postdate' => ''), $atts));
$out = '<div class="widget_postslist sc">';
$out .= '<ul>';
global $wpdb;
$myposts = get_posts("numberposts={$limit}&offset=0&cat={$cat_id}");
foreach ($myposts as $post) {
$post_date = $post->post_date;
$post_date = mysql2date('F j, Y', $post_date, false);
$out .= "<li>";
if ($thumb == "true") {
$thumbid = get_post_thumbnail_id($post->ID);
$imgsrc = wp_get_attachment_image_src($thumbid, array(9999, 9999));
$out .= '<div class="thumb"><a href="' . get_permalink($post->ID) . '" title="' . $post->post_title . '">';
if ($thumbid) {
$out .= atp_resize('', $imgsrc['0'], '50', '50', 'imgborder', '');
} else {
//$out .= '<img class="imgborder" src="'.THEME_URI.'/images/no-image.jpg'.'" alt="' .$post->post_title. '" />';
}
$out .= '</a></div>';
}
$out .= '<div class="pdesc"><a href="' . get_permalink($post->ID) . '" rel="bookmark">' . $post->post_title . '</a>';
if ($postdate == "true") {
$out .= '<div class="w-postmeta"><span>' . $post_date . '</span></div>';
} else {
$out .= '<p>' . wp_html_excerpt($post->post_content, $description, '...') . '</p>';
}
$out .= '</div></li>';
}
$out .= '</ul></div>';
return $out;
wp_reset_query();
}
示例14: get_years
function get_years()
{
global $wpdb;
$yearliest_year = $wpdb->get_results("SELECT YEAR(post_date) AS year\n FROM {$wpdb->posts}\n WHERE post_status = 'publish'\n AND post_type = 'post'\n ORDER BY post_date\n DESC LIMIT 1\n\n ");
//If there are any posts
if ($yearliest_year) {
$this_year = date('Y');
$months = array(1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June", 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December");
$current_year = $yearliest_year[0]->year;
while ($current_year > $this_year - 2) {
echo "<div class='fullDiv'><h3 class='year'><a href='/" . $current_year . "'>" . $current_year . "</a></h3>";
// echo "<h3><a href='". $current_year ."'> " . $current_year . " </a></h3>";
echo "<ul class='month_container'>";
foreach ($months as $month_num => $month) {
if ($search_month = $wpdb->query("SELECT MONTHNAME(post_date) as month\n\n FROM {$wpdb->posts}\n WHERE MONTHNAME(post_date) = '{$month}'\n AND YEAR(post_date) = {$current_year}\n AND post_type = 'post'\n AND post_status = 'publish'\n LIMIT 1\n\n ")) {
$countposts = get_posts("year={$current_year}&monthnum={$month_num}");
echo "<li class='month'><i class='s'>></i><a href='" . get_bloginfo('url') . "/" . $current_year . "/" . $month_num . "/'><span class='archive-month'>" . $month . "</span><span>" . count($countposts) . "</span></a></li>";
} else {
}
}
echo "</ul></div>";
$current_year--;
}
} else {
echo "No Posts Found.";
}
}
示例15: fruitframe_get_attachments
function fruitframe_get_attachments($id = NULL, $excludeIds = array())
{
if (!$id) {
$id = get_the_ID();
}
return get_posts(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'numberposts' => -1, 'orderby' => 'menu_order', 'post__not_in' => $excludeIds));
}