WP_Query PHP Class Code Examples

This page contains top rated real world PHP examples of class WP_Query extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: class_upfront_server_media_cleanup.php Project: sedici/wpmu-istec
0
 private function _get_cleanup_chunk()
 {
     $yesterday = strtotime("yesterday");
     $never_cleaned = new WP_Query(array('post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => -1, 'meta_query' => array('relation' => 'AND', array('key' => 'upfront_used_image_sizes', 'compare' => 'EXISTS'), array('key' => 'upfront_media_cleanup_time', 'value' => $yesterday, 'compare' => 'NOT EXISTS'))));
     $old_cleaned = new WP_Query(array('post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => -1, 'meta_query' => array('relation' => 'AND', array('key' => 'upfront_used_image_sizes', 'compare' => 'EXISTS'), array('key' => 'upfront_media_cleanup_time', 'value' => $yesterday, 'compare' => '<'))));
     return array_merge($never_cleaned->posts, $old_cleaned->posts);
 }
Example #2
Show file File: class-wp-rest-posts-controller.php Project: crazyyy/octagram
0
 /**
  * Get a collection of posts.
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function get_items($request)
 {
     $args = array();
     $args['author'] = $request['author'];
     $args['paged'] = $request['page'];
     $args['posts_per_page'] = $request['per_page'];
     $args['post_parent'] = $request['parent'];
     $args['post_status'] = $request['status'];
     $args['s'] = $request['search'];
     if (is_array($request['filter'])) {
         $args = array_merge($args, $request['filter']);
         unset($args['filter']);
     }
     // Force the post_type argument, since it's not a user input variable.
     $args['post_type'] = $this->post_type;
     /**
      * Filter the query arguments for a request.
      *
      * Enables adding extra arguments or setting defaults for a post
      * collection request.
      *
      * @param array           $args    Key value array of query var to query value.
      * @param WP_REST_Request $request The request used.
      */
     $args = apply_filters('rest_post_query', $args, $request);
     $query_args = $this->prepare_items_query($args);
     $posts_query = new WP_Query();
     $query_result = $posts_query->query($query_args);
     $posts = array();
     foreach ($query_result as $post) {
         if (!$this->check_read_permission($post)) {
             continue;
         }
         $data = $this->prepare_item_for_response($post, $request);
         $posts[] = $this->prepare_response_for_collection($data);
     }
     $response = rest_ensure_response($posts);
     $count_query = new WP_Query();
     unset($query_args['paged']);
     $query_result = $count_query->query($query_args);
     $total_posts = $count_query->found_posts;
     $response->header('X-WP-Total', (int) $total_posts);
     $max_pages = ceil($total_posts / $request['per_page']);
     $response->header('X-WP-TotalPages', (int) $max_pages);
     $base = add_query_arg($request->get_query_params(), rest_url('/wp/v2/' . $this->get_post_type_base($this->post_type)));
     if ($request['page'] > 1) {
         $prev_page = $request['page'] - 1;
         if ($prev_page > $max_pages) {
             $prev_page = $max_pages;
         }
         $prev_link = add_query_arg('page', $prev_page, $base);
         $response->link_header('prev', $prev_link);
     }
     if ($max_pages > $request['page']) {
         $next_page = $request['page'] + 1;
         $next_link = add_query_arg('page', $next_page, $base);
         $response->link_header('next', $next_link);
     }
     return $response;
 }
Example #3
Show file File: class-wc-sage-erp-connector-integration.php Project: nikolov-tmw/woocommerce-sage-erp-connector
0
 /**
  * Get the number of orders that are not exported
  * Note this only includes orders where the 'is_exported' meta is set to 0
  * Orders placed prior to the installation / activation of the plugin will be counted as exported
  *
  * @since 1.0
  * @return int number of unexported orders
  */
 private function get_order_count()
 {
     $query_args = array('fields' => 'ids', 'post_type' => 'shop_order', 'post_status' => isset($_GET['post_status']) ? $_GET['post_status'] : 'any', 'meta_query' => array(array('key' => '_wc_sage_erp_exported', 'value' => 0)), 'nopaging' => true);
     $query = new WP_Query($query_args);
     $unexported = count($query->posts);
     $query_args['meta_query'][0]['value'] = 1;
     $query = new WP_Query($query_args);
     $exported = count($query->posts);
     return array('unexported' => $unexported, 'exported' => $exported);
 }
Example #4
Show file File: ajax.php Project: imranshafqat/wp-project-manager
0
 function all_search()
 {
     $project_id = isset($_POST['project_id']) ? $_POST['project_id'] : false;
     $item = trim($_POST['item']);
     if (!$project_id) {
         $args = array('post_type' => array('project', 'task_list', 'task', 'message', 'milestone'), 'post_status' => 'publish', 'posts_per_page' => '-1', 's' => $item);
         $args = apply_filters('cpm_all_project_search_query_arg', $args, $item);
         $query = new WP_Query($args);
         $posts = $query->posts;
     }
     if ($project_id) {
         $args = array('post_type' => array('task_list', 'message', 'milestone'), 'post_status' => 'publish', 'post_parent' => $project_id, 'posts_per_page' => '-1', 's' => $item);
         $query = new WP_Query($args);
         global $wpdb;
         $sql = "SELECT * FROM {$wpdb->posts} AS p\n                LEFT JOIN {$wpdb->posts} AS tl ON p.ID=tl.post_parent\n                LEFT JOIN {$wpdb->posts} AS tk ON tl.ID=tk.post_parent\n                WHERE\n                p.post_type='project' AND p.post_status='publish' AND p.ID={$project_id}\n                AND  tl.post_type='task_list' AND tk.post_type='task'\n                AND  tl.post_status='publish' AND tk.post_status='publish'\n                AND ( tk.post_title like '%{$item}%' OR tk.post_content like '%{$item}%' )";
         $posts = $wpdb->get_results($sql);
         $posts = array_merge($query->posts, $posts);
     }
     $url = array();
     $items = array();
     foreach ($posts as $key => $post) {
         switch ($post->post_type) {
             case 'project':
                 $url = cpm_url_project_details($post->ID);
                 $category = __('Project: ', 'cpm');
                 $items[] = array('label' => '<div class="cpm-all-search-item"><a href="' . $url . '"><strong>' . $category . '</strong>' . $post->post_title . '</a></div>');
                 break;
             case 'task_list':
                 $url = cpm_url_single_tasklist($post->post_parent, $post->ID);
                 $category = __('Task List: ', 'cpm');
                 $items[] = array('label' => '<div class="cpm-all-search-item"><a href="' . $url . '"><strong>' . $category . '</strong>' . $post->post_title . '</a></div>');
                 break;
             case 'task':
                 $task_list = get_post($post->post_parent);
                 $url = cpm_url_single_task($task_list->post_parent, $post->post_parent, $post->ID);
                 $category = __('Task: ', 'cpm');
                 $items[] = array('label' => '<div class="cpm-all-search-item"><a href="' . $url . '"><strong>' . $category . '</strong>' . $post->post_title . '</a></div>');
                 break;
             case 'message':
                 $url = cpm_url_single_message($post->post_parent, $post->ID);
                 $category = __('Message: ', 'cpm');
                 $items[] = array('label' => '<div class="cpm-all-search-item"><a href="' . $url . '"><strong>' . $category . '</strong>' . $post->post_title . '</a></div>');
                 break;
             case 'milestone':
                 $url = cpm_url_milestone_index($post->post_parent);
                 $category = __('Milestone: ', 'cpm');
                 $items[] = array('label' => '<div class="cpm-all-search-item"><a href="' . $url . '"><strong>' . $category . '</strong>' . $post->post_title . '</a></div>');
                 break;
         }
     }
     if (!count($items)) {
         $items[] = array('label' => '<div class="cpm-all-search-item"><strong>' . __('No item found !', 'cpm') . '</strong></div>');
     }
     $search_details = json_encode($items);
     wp_send_json_success($search_details);
 }
Example #5
Show file File: portfolio.php Project: RDePoppe/luminaterealestate
0
 function widget($args, $instance)
 {
     extract($args);
     $instance = wp_parse_args((array) $instance, self::$widget_defaults);
     /* Our variables from the widget settings. */
     $title = apply_filters('widget_title', $instance['title']);
     $args = array('no_found_rows' => 1, 'posts_per_page' => $instance['show'], 'post_type' => 'dt_portfolio', 'post_status' => 'publish', 'orderby' => $instance['orderby'], 'order' => $instance['order'], 'tax_query' => array(array('taxonomy' => 'dt_portfolio_category', 'field' => 'term_id', 'terms' => $instance['cats'])));
     switch ($instance['select']) {
         case 'only':
             $args['tax_query'][0]['operator'] = 'IN';
             break;
         case 'except':
             $args['tax_query'][0]['operator'] = 'NOT IN';
             break;
         default:
             unset($args['tax_query']);
     }
     $p_query = new WP_Query($args);
     // for usage as shortcode
     if (!isset($img_size)) {
         $img_size = array($instance['max_width'], $instance['max_width']);
     }
     if (!isset($img_size_origin)) {
         $img_size_origin = $img_size;
     } else {
         $p = $img_size[1] / $img_size[0];
         $img_size_origin[1] = round($img_size_origin[0] * $p);
     }
     echo $before_widget;
     // title
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     if ($p_query->have_posts()) {
         update_post_thumbnail_cache($p_query);
         echo '<div class="instagram-photos" data-image-max-width="' . absint($instance['max_width']) . '">';
         while ($p_query->have_posts()) {
             $p_query->the_post();
             $thumb_id = get_post_thumbnail_id(get_the_ID());
             if (!has_post_thumbnail(get_the_ID())) {
                 $args = array('posts_per_page' => 1, 'no_found_rows' => 1, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_status' => 'inherit');
                 $images = new WP_Query($args);
                 if ($images->have_posts()) {
                     $thumb_id = $images->posts[0]->ID;
                 }
             }
             $thumb_meta = wp_get_attachment_image_src($thumb_id, 'full');
             dt_get_thumb_img(array('img_meta' => $thumb_meta ? $thumb_meta : null, 'img_id' => $thumb_id, 'use_noimage' => true, 'class' => 'post-rollover', 'title' => get_the_title(), 'href' => get_permalink(), 'options' => array('w' => $img_size_origin[0], 'h' => $img_size_origin[1]), 'wrap' => "\n" . '<a %HREF% %TITLE% %CLASS% %CUSTOM%><img %IMG_CLASS% %SRC% ' . image_hwstring($img_size[0], $img_size[1]) . ' %ALT% /></a>' . "\n"));
         }
         // while have posts
         wp_reset_postdata();
         echo '</div>';
     }
     // if have posts
     echo $after_widget;
 }
Example #6
Show file File: frame_functions_old.php Project: loevendahl/flexbil
0
/**
 * TABS - latest
 *
 * get latest posts for tabs
 * @since 7.0
 */
function bizz_tabs_latest($posts = 5, $size = 35)
{
    global $wp_version;
    if (version_compare($wp_version, '3.0.9', '>=')) {
        $the_query = new WP_Query('showposts=' . $posts . '&ignore_sticky_posts=1&orderby=post_date&order=desc');
    } else {
        $the_query = new WP_Query('showposts=' . $posts . '&caller_get_posts=1&orderby=post_date&order=desc');
    }
    while ($the_query->have_posts()) {
        $the_query->the_post();
        $featured_exists = bizz_image('key=image&return=true');
        ?>

<li>
	<?php 
        if ($size != 0) {
            bizz_image('key=image&width=' . $size . '&height=' . $size . '&class=thumbnail');
        }
        ?>

	<?php 
        if (isset($featured_exists) && !empty($featured_exists)) {
            ?>

		<div class="list-right">
	<?php 
        }
        ?>

	<a title="<?php 
        the_title();
        ?>
" href="<?php 
        the_permalink();
        ?>
"><?php 
        the_title();
        ?>
</a>
	<span class="meta"><?php 
        the_time('M j, Y');
        ?>
</span>
	<?php 
        if (isset($featured_exists) && !empty($featured_exists)) {
            ?>

		</div>
	<?php 
        }
        ?>

	<div class="fix"></div>
</li>
<?php 
    }
}
Example #7
Show file File: ht_zero_hits.php Project: meowrika/govintranet
0
function zh_show_dashboard()
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.', 'govintranet'));
    }
    $posttypes = get_option('options_zh_post_types');
    $inq = 0;
    echo "<table class='table table-striped'>\n\t<thead>\n\t<tr>\n\t<td>" . __('Content type', 'govintranet') . "</td>\n\t<td>" . __('6 months', 'govintranet') . "</td>\n\t<td>" . __('1 year', 'govintranet') . "</td>\n\t<td>" . __('Patrol', 'govintranet') . "</td>\n\t</tr>\n\t</thead>\n\t<tbody>";
    if ($posttypes) {
        foreach ($posttypes as $pt) {
            echo "<tr>";
            $inq = 0;
            $obj = get_post_type_object($pt);
            $pt_singular = $obj->labels->singular_name;
            $pt_plural = $obj->labels->name;
            echo "<td><a href='" . admin_url('/tools.php?page=zero_hits&action=generate&ptype[]=' . $pt . '&show=all') . "'>" . $pt_plural . "</a></td>";
            $allposts = new WP_Query(array('post_type' => $pt, 'posts_per_page' => -1, 'post_status' => 'publish', 'date_query' => array(array('before' => array('year' => date('Y'), 'month' => date('n'), 'day' => 1), 'inclusive' => false)), 'meta_query' => array(array('key' => 'zh_total_6m', 'value' => 0))));
            $inq .= $allposts->found_posts;
            echo "<td";
            if ($allposts->found_posts > 0) {
                echo " class='text-warning'>";
                echo "<a href='" . admin_url('/tools.php?page=zero_hits&action=generate&ptype[]=' . $pt . '&show=6m') . "'>";
                echo sprintf(__('%d not viewed', 'govintranet'), $allposts->found_posts);
                echo "</a>";
            } else {
                echo " class='text-success'>" . __("Active", "govintranet");
            }
            echo "</td>";
            $allposts = new WP_Query(array('post_type' => $pt, 'posts_per_page' => -1, 'post_status' => 'publish', 'date_query' => array(array('before' => array('year' => date('Y'), 'month' => date('n'), 'day' => 1), 'inclusive' => false)), 'meta_query' => array(array('key' => 'zh_total_1y', 'value' => 0))));
            $inq .= $allposts->found_posts;
            echo "<td";
            if ($allposts->found_posts > 0) {
                echo " class='text-danger'>";
                echo "<a href='" . admin_url('/tools.php?page=zero_hits&action=generate&ptype[]=' . $pt . '&show=1y') . "'>";
                echo sprintf(__('%d not viewed', 'govintranet'), $allposts->found_posts);
                echo "</a>";
            } else {
                echo " class='text-success'>" . __("Active", "govintranet");
            }
            echo "</td>";
            $args = array('post_type' => $pt, 'posts_per_page' => -1, 'post_status' => 'publish', 'date_query' => array(array('before' => array('year' => date('Y'), 'month' => date('n'), 'day' => 1), 'inclusive' => false)), 'meta_query' => array('relation' => 'OR', array('key' => 'zh_last_processed', 'value' => date('Ym01'), 'compare' => "<", 'type' => 'DATETIME'), array('key' => 'zh_last_processed', 'compare' => "NOT EXISTS")));
            $allposts = new WP_Query($args);
            $inq .= $allposts->found_posts;
            echo "<td>";
            if ($allposts->found_posts > 0) {
                echo '<span class="dashicons dashicons-update"></span> ' . sprintf(__('%d queued', 'govintranet'), $allposts->found_posts);
            } else {
                echo '<span class="dashicons dashicons-yes"></span> ' . __("Up to date", "govintranet");
            }
            echo "</td>";
            echo "</tr>";
        }
    }
    echo "</tbody></table>";
    if (get_option('zh_patrol_end') != "") {
        echo "<p>" . sprintf(__('Last patrol finished at %s', 'govintranet'), get_option('zh_patrol_end')) . "</p>";
    }
}
Example #8
Show file File: class-root-around-relationships.php Project: fullsteamlabs/root-around
0
 public function get_Relationships_by_Tag($tag, $_method, $_route, $_path, $_headers)
 {
     if (empty($tag) || !is_string($tag)) {
         return new WP_Error('json_options_invalid_tag', __("Invalid options tag"), ['status' => 404]);
     }
     $site = $_headers['REMOTE'];
     $tags = explode(',', $tag);
     if ($tags) {
         $tags_query['relation'] = 'OR';
         foreach ($tags as $tag) {
             $tags_query[] = array('key' => 'related_tags', 'value' => $tag, 'compare' => 'LIKE');
         }
     }
     $args = array('post_type' => 'relationship', 'meta_query' => array('relation' => 'AND', array('key' => 'site_address', 'value' => $site), $tags_query));
     $relationships = new WP_Query($args);
     if ($relationships->have_posts()) {
         // Get the Target Categories
         $targets = [];
         while ($relationships->have_posts()) {
             $relationships->the_post();
             $targets[] = get_field('target_category');
         }
         $targets = dedupe($targets);
         $related_categories = implode(', ', $targets);
         // Find Matching Relationships
         $args = array('post_type' => 'relationship', 'tax_query' => array(array('taxonomy' => 'related_categories', 'terms' => $related_categories)));
         $relationships = new WP_Query($args);
         // Build Relationships JSON Reponse
         include 'related-json-response.php';
     }
     wp_reset_query();
     return $sites;
 }
Example #9
Show file File: post.php Project: gilbitron/wp-cli
0
 /**
  * Get a list of posts.
  *
  * ## OPTIONS
  *
  * [--<field>=<value>]
  * : One or more args to pass to WP_Query.
  *
  * [--field=<field>]
  * : Prints the value of a single field for each post.
  *
  * [--fields=<fields>]
  * : Limit the output to specific object fields.
  *
  * [--format=<format>]
  * : Accepted values: table, csv, json, count, ids. Default: table
  *
  * ## AVAILABLE FIELDS
  *
  * These fields will be displayed by default for each post:
  *
  * * ID
  * * post_title
  * * post_name
  * * post_date
  * * post_status
  *
  * These fields are optionally available:
  *
  * * post_author
  * * post_date_gmt
  * * post_content
  * * post_excerpt
  * * comment_status
  * * ping_status
  * * post_password
  * * to_ping
  * * pinged
  * * post_modified
  * * post_modified_gmt
  * * post_content_filtered
  * * post_parent
  * * guid
  * * menu_order
  * * post_type
  * * post_mime_type
  * * comment_count
  * * filter
  * * url
  *
  * ## EXAMPLES
  *
  *     wp post list --field=ID
  *
  *     wp post list --post_type=post --posts_per_page=5 --format=json
  *
  *     wp post list --post_type=page --fields=post_title,post_status
  *
  *     wp post list --post_type=page,post --format=ids
  *
  *     wp post list --post__in=1,3
  *
  * @subcommand list
  */
 public function list_($_, $assoc_args)
 {
     $formatter = $this->get_formatter($assoc_args);
     $defaults = array('posts_per_page' => -1, 'post_status' => 'any');
     $query_args = array_merge($defaults, $assoc_args);
     foreach ($query_args as $key => $query_arg) {
         if (false !== strpos($key, '__') || 'post_type' == $key && 'any' != $query_arg) {
             $query_args[$key] = explode(',', $query_arg);
         }
     }
     if ('ids' == $formatter->format) {
         $query_args['fields'] = 'ids';
         $query = new WP_Query($query_args);
         echo implode(' ', $query->posts);
     } else {
         if ('count' === $formatter->format) {
             $query_args['fields'] = 'ids';
             $query = new WP_Query($query_args);
             $formatter->display_items($query->posts);
         } else {
             $query = new WP_Query($query_args);
             $posts = array_map(function ($post) {
                 $post->url = get_permalink($post->ID);
                 return $post;
             }, $query->posts);
             $formatter->display_items($posts);
         }
     }
 }
Example #10
Show file File: apn-site-plugin.php Project: hktang/apn-wp-plugin
0
/** Return the person list according to conditions by $args
 *  @param  mixed   $args
 *  @param  mixed   $terms
 *
 *  @return string  $member_list_sorted
 */
function apn2015_get_people_list_sorted($args, $terms)
{
    $member_list_sorted = '';
    if ($terms != false) {
        foreach ($terms as $term) {
            $args[$term->taxonomy] = $term->slug;
            $query = new WP_Query($args);
            if ($query->have_posts()) {
                $term_name = $term->name;
                $pos = strpos($term_name, '--');
                if (!$args['sort_filter']) {
                    /* regular sort */
                    if (apn2015_get_people_list($args) !== false) {
                        $member_list_sorted .= '<h3 class="list-criteria">' . $term_name . '</h3>';
                    }
                    $member_list_sorted .= apn2015_get_people_list($args);
                } elseif ($pos > 0) {
                    /* filtered sort: only shows terms that matches the sort_filter prefix */
                    $term_title = substr($term_name, $pos + 2);
                    $term_prefix = strtolower(substr($term->name, 0, $pos - 1));
                    if ($term_prefix == $args['sort_filter']) {
                        $member_list_sorted .= '<h3 class="list-criteria">' . $term_title . '</h3>';
                        $member_list_sorted .= apn2015_get_people_list($args);
                    }
                }
            }
        }
    } else {
        $query = new WP_Query($args);
        if ($query->have_posts()) {
            $member_list_sorted .= apn2015_get_people_list($args);
        }
    }
    return $member_list_sorted;
}
Example #11
Show file File: base.php Project: poneisme/Lion
0
function lion_post_list($type = 'latest', $num = 5)
{
    if ($type == 'popular') {
        $the_query = new WP_Query(array('posts_per_page' => $num, 'orderby' => 'meta_value_num', 'meta_key' => '_post_like'));
    } elseif ($type == 'modified') {
        $the_query = new WP_Query(array('posts_per_page' => $num, 'orderby' => 'modified'));
    } else {
        $the_query = new WP_Query(array('posts_per_page' => $num, 'orderby' => 'latest'));
    }
    $post_list = '';
    while ($the_query->have_posts()) {
        $the_query->the_post();
        $post_list .= '<li class="list-item u-clearfix"><a href="' . get_permalink() . '" title="' . get_the_title() . '"><div class="list-item-image';
        if (!lion_is_has_image()) {
            $post_list .= ' no-image';
        }
        $post_list .= ' u-floatLeft" style="background-image:url(' . get_post_thumbnail() . ')"></div><div class="list-item-title">' . get_the_title() . '</div><div class="list-item-meta">' . get_the_date('Y-m-d');
        if (function_exists('wpl_get_like_count')) {
            $post_list .= '<span class="middotDivider"></span>' . wpl_get_like_count() . ' likes';
        }
        $post_list .= '</div></a></li>';
    }
    wp_reset_postdata();
    return $post_list;
}
Example #12
Show file File: feedwordpress.php Project: runderwo/feedwordpress
0
 public function feedwordpress_cleanup()
 {
     if (get_option('feedwordpress_process_zaps', null)) {
         $q = new WP_Query(array('fields' => '_synfrom', 'post_status' => 'fwpzapped', 'ignore_sticky_posts' => true, 'meta_key' => '_feedwordpress_zapped_blank_me', 'meta_value' => 1));
         if ($q->have_posts()) {
             foreach ($q->posts as $p) {
                 $post_id = $p->ID;
                 $revisions = wp_get_post_revisions($post_id, array("check_enabled" => false));
                 # Now nuke the content of the post & its revisions
                 set_post_field('post_content', '', $post_id);
                 set_post_field('post_excerpt', '', $post_id);
                 foreach ($revisions as $rev) {
                     set_post_field('post_content', '', $rev->ID);
                     set_post_field('post_excerpt', '', $rev->ID);
                 }
                 # Un-tag it for blanking.
                 delete_post_meta($p->ID, '_feedwordpress_zapped_blank_me');
                 # Don't remove old_status indicator. A later
                 # update from the feed may cause us to once
                 # again have some content so we can un-zap.
             }
         }
         $q = new WP_Query(array('fields' => '_synfrom', 'post_status' => 'fwpzapped', 'ignore_sticky_posts' => true, 'meta_key' => '_feedwordpress_zapped_blank_me', 'meta_value' => 2));
         if ($q->have_posts()) {
             foreach ($q->posts as $p) {
                 update_post_meta($p->ID, '_feedwordpress_zapped_blank_me', 1);
             }
         }
         update_option('feedwordpress_process_zaps', 0);
     }
 }
Example #13
Show file File: timber-query-iterator.php Project: dleatherman/timbangular-js
0
 public function __construct($query = false, $posts_class = 'TimberPost')
 {
     add_action('pre_get_posts', array($this, 'fix_number_posts_wp_quirk'));
     if ($posts_class) {
         $this->_posts_class = $posts_class;
     }
     if (is_a($query, 'WP_Query')) {
         // We got a full-fledged WP Query, look no further!
         $the_query = $query;
     } elseif (false === $query) {
         // If query is explicitly set to false, use the main loop
         global $wp_query;
         $the_query =& $wp_query;
     } elseif (TimberHelper::is_array_assoc($query) || is_string($query) && strstr($query, '=')) {
         // We have a regularly formed WP query string or array to use
         $the_query = new WP_Query($query);
     } elseif (is_numeric($query) || is_string($query)) {
         // We have what could be a post name or post ID to pull out
         $the_query = self::get_query_from_string($query);
     } elseif (is_array($query) && count($query) && (is_integer($query[0]) || is_string($query[0]))) {
         // We have a list of pids (post IDs) to extract from
         $the_query = self::get_query_from_array_of_ids($query);
     } elseif (is_array($query) && empty($query)) {
         // it's an empty array
         $the_query = array();
     } else {
         TimberHelper::error_log('I have failed you! in ' . basename(__FILE__) . '::' . __LINE__);
         TimberHelper::error_log($query);
         // We have failed hard, at least let get something.
         $the_query = new WP_Query();
     }
     $this->_query = $the_query;
 }
Example #14
Show file File: tidal.php Project: gopinathshiva/wordpress-vip-plugins
0
 /**
  * Retrieve a Tidal-contributed post or Tidal Contributor post by Tidal ID.
  *
  * @param array $args Method parameters. Contains:
  *                    - int     $blog_id
  *                    - string  $username
  *                    - string  $password
  *                    - string  $tidal_id
  *
  * @return int Wordpress post ID.
  */
 function tidal_getPostID($args)
 {
     global $wp_xmlrpc_server;
     if (count($args) < 4) {
         return $wp_xmlrpc_server->error = new IXR_Error(400, esc_html__('Insufficient arguments passed to this XML-RPC method.', 'tidal'));
     }
     $wp_xmlrpc_server->escape($args);
     $blog_id = (int) $args[0];
     $username = $args[1];
     $password = $args[2];
     $tidal_id = (string) $args[3];
     if (!($user = $wp_xmlrpc_server->login($username, $password))) {
         return $wp_xmlrpc_server->error;
     }
     $post_id = 0;
     // Check if ID corresponds to a Tidal-contributed post
     $query = new WP_Query(array('post_type' => 'post', 'post_status' => 'any', 'meta_query' => array(array('key' => $this::tidal_id_meta, 'value' => $tidal_id))));
     if (!empty($query->posts)) {
         $post_id = $query->posts[0]->ID;
     }
     // Check if ID corresponds to a Tidal contributor
     $query = new WP_Query(array('post_type' => $this::post_type, 'name' => $tidal_id));
     if (!empty($query->posts)) {
         $post_id = $query->posts[0]->ID;
     }
     if (empty($post_id)) {
         return new IXR_Error(404, esc_html__('Invalid post Tidal ID.', 'tidal'));
     }
     if (!current_user_can('edit_post', $post_id)) {
         return new IXR_Error(401, esc_html__('Sorry, you cannot edit this post.', 'tidal'));
     }
     return $post_id;
 }
Example #15
Show file File: misc.php Project: SayenkoDesign/ividf
0
function ompf_get_portfolio_root_page($portfolio_post_id)
{
    $args = array('post_type' => 'page', 'posts_per_page' => 1, 'meta_query' => array(array('key' => 'ompf_portfolio_display', 'value' => '1')));
    $terms = get_the_terms($portfolio_post_id, 'portfolio-type');
    if (!empty($terms)) {
        $term = reset($terms);
        if ($term->parent) {
            $term = get_term($term->parent, 'portfolio-type');
            while ($term->parent) {
                $term = get_term($term->parent, 'portfolio-type');
            }
        }
        $args['meta_query'][] = array('key' => 'ompf_portfolio_categories', 'value' => array('0', '', $term->term_id), 'compare' => 'IN');
    }
    $tmp_q = new WP_Query($args);
    if ($tmp_q->post_count) {
        $portfolio_page = $tmp_q->posts[0];
    } else {
        unset($args['meta_query'][1]);
        $tmp_q = new WP_Query($args);
        if ($tmp_q->post_count) {
            $portfolio_page = $tmp_q->posts[0];
        } else {
            $portfolio_page = false;
        }
    }
    wp_reset_postdata();
    return $portfolio_page;
}
Example #16
Show file File: class-tei-dom.php Project: adisonc/MaineLearning
0
 public function buildProjectData()
 {
     $args = array('post_parent' => $this->projectData['project_id'], 'post_type' => 'anth_part', 'orderby' => 'menu_order', 'posts_per_page' => -1, 'order' => 'ASC');
     $partsData = new WP_Query($args);
     $partObjectsArray = $partsData->posts;
     $partNumber = 0;
     foreach ($partObjectsArray as $partObject) {
         $newPart = $this->newPart($partObject);
         $newPart->setAttribute('n', $partNumber);
         $newPart->setAttribute('xml:id', "body-{$partNumber}");
         $args = array('post_parent' => $partObject->ID, 'post_type' => 'anth_library_item', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC');
         $libraryItemsData = new WP_Query($args);
         $libraryItemObjectsArray = $libraryItemsData->posts;
         $itemNumber = 0;
         foreach ($libraryItemObjectsArray as $libraryItemObject) {
             $origPostData = get_post_meta($libraryItemObject->ID, 'anthologize_meta', true);
             $libraryItemObject->original_post_id = isset($origPostData['original_post_id']) ? $origPostData['original_post_id'] : false;
             $newItem = $this->newItem($libraryItemObject);
             $newItem->setAttribute('xml:id', "body-{$partNumber}-{$itemNumber}");
             if ($this->includeStructuredSubjects) {
                 $this->addStructuredSubjects($libraryItemObject->original_post_id);
             }
             $newItem->setAttribute('n', $itemNumber);
             $newPart->appendChild($newItem);
             $itemNumber++;
         }
         $this->bodyNode->appendChild($newPart);
         $partNumber++;
     }
 }
Example #17
Show file File: et-pagebuilder.php Project: sradagan/Divi
0
function et_pb_show_all_layouts()
{
    if (!wp_verify_nonce($_POST['et_load_nonce'], 'et_load_nonce')) {
        die(-1);
    }
    printf('
		<label for="et_pb_load_layout_replace">
			<input name="et_pb_load_layout_replace" type="checkbox" id="et_pb_load_layout_replace" %2$s/>
			%1$s
		</label>', __('Replace the existing content with loaded layout', 'Divi'), checked(get_theme_mod('et_pb_replace_content', 'on'), 'on', false));
    $query = new WP_Query(array('meta_query' => array(array('key' => '_et_pb_predefined_layout', 'value' => 'on', 'compare' => 'NOT EXISTS')), 'post_type' => 'et_pb_layout', 'posts_per_page' => '-1'));
    if ($query->have_posts()) {
        printf('<h3>%1$s</h3>', __('Saved Layouts:'));
        echo '<ul class="et-pb-all-modules et-pb-load-layouts">';
        while ($query->have_posts()) {
            $query->the_post();
            printf('<li class="et_pb_text" data-layout_id="%2$s">%1$s<span class="et_pb_layout_buttons"><a href="#" class="button-primary et_pb_layout_button_load">Load</a><a href="#" class="button et_pb_layout_button_delete">Delete</a></span></li>', get_the_title(), get_the_ID());
        }
        echo '</ul>';
    }
    wp_reset_postdata();
    $query = new WP_Query(array('meta_key' => '_et_pb_predefined_layout', 'meta_value' => 'on', 'post_type' => 'et_pb_layout', 'posts_per_page' => '-1', 'order' => 'ASC', 'orderby' => 'date'));
    if ($query->have_posts()) {
        printf('<h3>%1$s</h3>', __('Predefined Layouts:'));
        echo '<ul class="et-pb-all-modules et-pb-load-layouts">';
        while ($query->have_posts()) {
            $query->the_post();
            printf('<li class="et_pb_text" data-layout_id="%2$s">%1$s<span class="et_pb_layout_buttons"><a href="#" class="button-primary et_pb_layout_button_load">Load</a></span></li>', get_the_title(), get_the_ID());
        }
        echo '</ul>';
    }
    wp_reset_postdata();
    die;
}
Example #18
Show file File: class-ccf-export.php Project: misfist/missdrepants-network
0
 /**
  * We need to reattach form fields and field choices
  *
  * @since 6.5
  */
 public function action_import_end()
 {
     $forms = new WP_Query(array('post_type' => 'ccf_form', 'posts_per_page' => 1000, 'no_found_rows' => true));
     if ($forms->have_posts()) {
         foreach ($forms->posts as $form) {
             $cleanup = get_post_meta($form->ID, 'ccf_import_cleanup', true);
             if (!empty($cleanup)) {
                 $fields = wp_list_pluck(get_children(array('post_type' => 'ccf_field', 'post_parent' => $form->ID, 'numberposts' => 500)), 'ID');
                 if (!empty($fields)) {
                     $fields = array_values($fields);
                 }
                 update_post_meta($form->ID, 'ccf_attached_fields', $fields);
                 delete_post_meta($form->ID, 'ccf_import_cleanup');
             }
         }
     }
     $fields = new WP_Query(array('post_type' => 'ccf_field', 'posts_per_page' => 2000, 'no_found_rows' => true));
     if ($fields->have_posts()) {
         foreach ($fields->posts as $field) {
             $cleanup = get_post_meta($field->ID, 'ccf_import_cleanup', true);
             if (!empty($cleanup)) {
                 $choices = wp_list_pluck(get_children(array('post_type' => 'ccf_choice', 'post_parent' => $field->ID, 'numberposts' => 500)), 'ID');
                 if (!empty($choices)) {
                     $choices = array_values($choices);
                 }
                 update_post_meta($field->ID, 'ccf_attached_fields', $choices);
                 delete_post_meta($field->ID, 'ccf_import_cleanup');
             }
         }
     }
 }
Example #19
Show file File: functions.php Project: nguyenvanvu/bds
0
function cw_magazine_show_posts($name_categ, $id_cat)
{
    if ($name_categ) {
        echo '<div class="half-page front-page-boxes customfp">';
        echo '<ul>';
        echo '<li class="title-categ"><span>' . $name_categ . '</span></li>';
        $args = array('showposts' => 5, 'cat' => $id_cat);
        $cw_query = new WP_Query($args);
        if ($cw_query->have_posts()) {
            while ($cw_query->have_posts()) {
                $cw_query->the_post();
                echo '<li>';
                echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '">';
                the_post_thumbnail(array(75, 75), array('class' => 'alignleft'));
                echo '</a>';
                echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '">';
                the_title();
                echo '</a>';
                echo '<p class=""> - ' . the_time(get_option('time_format')) . ' ' . comments_number() . '</p>';
                echo '</li>';
            }
        }
        /* Restore original Post Data */
        wp_reset_postdata();
        echo '</ul>';
        echo '</div>';
    } else {
        $categories = get_categories();
        if (isset($categories) && !empty($categories)) {
            echo '<div class="half-page front-page-boxes">';
            echo '<ul>';
            echo '<li class="title-categ"><span>' . $categories[0]->name . '</span></li>';
            $args = array('showposts' => 5, 'cat' => $categories[0]->cat_ID);
            $cw_query = new WP_Query($args);
            if ($cw_query->have_posts()) {
                while ($cw_query->have_posts()) {
                    $cw_query->the_post();
                    echo '<li>';
                    echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '">';
                    the_post_thumbnail(array(75, 75), array('class' => 'alignleft'));
                    echo '</a>';
                    echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '">';
                    the_title();
                    echo '</a>';
                    echo '<p class=""> - ' . the_time(get_option('time_format')) . ' ' . comments_number() . '</p>';
                    echo '</li>';
                }
            }
            /* Restore original Post Data */
            wp_reset_postdata();
            echo '</ul>';
            echo '</div>';
        }
    }
}