Example #1
0
 /**
  * AJAX action for searching posts by category and title/content
  */
 public function action_customize_control_post_search()
 {
     check_ajax_referer();
     if (current_user_can(Builder::get_capability())) {
         wp_send_json_success(wp_list_pluck((new \WP_Query(['post_type' => !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : 'post', 'cat' => !empty($_GET['category']) ? absint($_GET['category']) : 0, 'paged' => !empty($_GET['page']) ? absint($_GET['page']) : 1, 's' => !empty($_GET['s']) && String::length($s = sanitize_text_field($_GET['s'])) > static::MIN_CHARACTERS_NUMBER ? $s : '', 'update_post_meta_cache' => false, 'post__not_in' => array_values(Posts::get_ids())]))->get_posts(), 'post_title', 'ID'));
     }
     wp_send_json_error(__('You are not allowed to do it.'));
 }
Example #2
0
 /**
  * Display widget content on frontend
  *
  * @param array  $data
  * @param string $id
  * @param int    $number
  */
 public static function render_widget(array $data, $id, $number)
 {
     global $post;
     $post_id = !empty($data['post']['post_id']) ? absint($data['post']['post_id']) : 0;
     $post = Posts::get($post_id, static::$_post_type, "{$id}[post][post_id]");
     if (!empty($post)) {
         setup_postdata($post);
         the_title();
         the_excerpt();
         wp_reset_postdata();
     }
 }
Example #3
0
 /**
  * Save data in special option for better performance in query
  *
  * @param \WP_Customize_Setting $setting
  */
 protected function _save_post_id($setting)
 {
     Posts::update($setting->id, $setting->post_value());
 }