I need that this select worked here I have this code need a wordpress filter
I have a page of posts that needs to be filtered out by date I can not do that to work properly
<?php
if ($_GET['select'] == '2018') {
$order = "&orderby=date&order=DESC";
$s1 = ' selected="selected"';
}
if ($_GET['select'] == 'lastest') {
$order = "&orderby=date&order=ASC";
$s2 = ' selected="selected"';
}
if ($_GET['select'] == 'title') {
$order = "&orderby=title&order=ASC";
$s3 = ' selected="selected"';
}
if ($_GET['select'] == 'correct') {
$order = "&orderby=modified";
$s4 = ' selected="selected"';
}
?>
<form method="get" id="order">
<select name="select" onchange='this.form.submit()' style="width:200px">
<option value="2018"<?=$s1?>>2018</option>
<option value="lastest"<?=$s2?>>по дате (сначала старые)</option>
<option value="title"<?=$s3?>>по заголовку</option>
<option value="correct"<?=$s4?>>по дате изменения</option>
</select>
</form>
<?php
global $query_string; // параметры базового запроса
query_posts($query_string.'&'.$order); // базовый запрос + свои параметры
?>
<div class="news__page" id="container-01">
<?php
$args2 = array(
'category_name' => 'news-company',
'date_query' => array(
array(
'before' => array(
'year' => 2002,
),
'inclusive' => true,
),
),
'posts_per_page' => -1,
);
$loop = new WP_Query($args2 );
while ($loop->have_posts()) {
$loop->the_post();
?>
<div class="news-item pinto">
<div class="news-img">
<?php if ( has_post_thumbnail() ) : ?>
<a title="<?php the_title_attribute(); ?>" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
</div>
<div class="news-wrap">
<?php the_title(); ?>
<div class="news_text"><?php the_excerpt(); ?></div>
<span class="news-data"><?php echo get_the_date() ?></span>
</div>
</div>
<?php
}
?>
I need that this select worked here I have this code need a wordpress filter
I have a page of posts that needs to be filtered out by date I can not do that to work properly
http://prntscr.com/ksbdia
Related
I want to search post by post title exact match and after match from post content or similar match for e.g I want to search "getting pregnant" answer should be first exact match post-title and after match post-title like "get pregnant" or search from post content. below is my search code please guide me.
<?php
$args = array (
's' => $s,
'category__in' => $category,
'year' => $year,
'monthnum' => $monthnum,
'paged' => $paged,
'order' => $sortby,
'tax_query' => $filterq,
'post_status' => 'publish',
'orderby' => 'title',
);
$query = new WP_Query($args) ;
// print_r($query);
if ( $query->have_posts() ) :
echo '<ul>';
while ( $query->have_posts() ) : $query->the_post();
if(mom_option('search_page_ex') == true) {
if (is_type_page()) {
continue;
}
}
?>
<li <?php post_class(); ?> itemscope="" itemtype="http://schema.org/Article">
<?php if (mom_post_image() != false) { ?>
<figure class="post-thumbnail"><a href="<?php the_permalink(); ?>">
<?php mom_post_image_full('search-grid'); ?>
<span class="post-format-icon"></span>
</a></figure>
<?php } ?>
<?php if( mom_post_image() != false ) {
$mom_class = ' class="fix-right-content"';
} else {
$mom_class = '';
}
?>
<div<?php echo $mom_class; ?>>
<h2 itemprop="name"><a itemprop="url" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="entry-content">
<p>
<?php global $post;
$excerpt = $post->post_excerpt;
if($excerpt==''){
$excerpt = get_the_content('');
}
echo wp_html_excerpt(strip_shortcodes($excerpt), 115);
?> ...
</p>
</div>
<?php if($post_head != 0) { ?>
<div class="entry-meta">
<?php if($post_head_date != 0) { ?>
<time class="entry-date" datetime="<?php the_time('c'); ?>" itemprop="dateCreated"><i class="momizat-icon-calendar"></i><?php echo mom_date_format(); ?></time>
<?php } ?>
<?php if($post_head_commetns != 0) { ?>
<div class="comments-link">
<i class="momizat-icon-bubbles4"></i><?php comments_number(__( '(0) Comments', 'framework' ), __( '(1) Comment', 'framework' ),__( '(%) Comments', 'framework' )); ?>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
</li>
<?php endwhile;
echo '</ul>'; ?>
Ok so I have a sidebar widget that pulls in from a list of posts from a custom post type, which itself pulls in from all other custom post types. I need to display the list of posts from tab 2 in this sidebar on a page as a list of posts like an archive. This is the code that pulls in the posts for the sidebar:
<?php
// Prevent loading this file directly
defined( 'ABSPATH' ) || exit;
class ChemTabs extends WP_Widget {
function __construct() {
parent::__construct(
'tabs', _('Tabs Widget'),
array(
'description' => _('A tabs widget.'),
));
}
private function ce_getPostClass($style, $index) {
switch ($style) {
case 'first-up':
if ( $index == 0 ) return 'first-up';
else return 'list-type';
break;
default:
return $style;
}
}
private function ce_has($listStyle, $index, $post) {
$class = $this->ce_getPostClass($listStyle, $index);
$has = array(
'thumb' => false,
'terms' => true,
'date' => true,
'content' => false,
'excerpt' => false,
'title' => true,
'video' => false,
'webinarDate' => false
);
switch ($class) {
case 'first-up':
$has['thumb'] = true;
$has['excerpt'] = true;
break;
case 'list-type':
$has['terms'] = false;
break;
case 'thumblist':
$has['thumb'] = true;
break;
case 'single': // no need for this anymore probably
$has['content'] = true;
break;
}
switch ($post->post_type) {
case 'video':
$has['video'] = true;
break;
case 'webinar':
$has['webinarDate'] = true;
break;
}
return $has;
}
public function widget( $args, $instance ) {
global $post;
$instance['tab_1_title'] = isset($instance['tab_1_title'])?$instance['tab_1_title']:'Tab 1';
$instance['tab_2_title'] = isset($instance['tab_2_title'])?$instance['tab_2_title']:'Tab 2';
$instance['storylist_id_1'] = isset($instance['storylist_id_1']) ? $instance['storylist_id_1'] : '';
$instance['storylist_id_2'] = isset($instance['storylist_id_2']) ? $instance['storylist_id_2'] : '';
$instance['n'] = isset($instance['n']) ? $instance['n'] : 4;
$title = isset($instance['title'])?$instance['title']:'';
$type = isset($instance['type'])?$instance['type']:'color';
$class = isset($instance['class'])?$instance['class']:'brand-primary';
// Post list configuration
// Note: posts temporarily rendered with ajax
$list_style = isset($instance['listStyle'])?$instance['listStyle']:'thumblist';
$list_post_type = isset($instance['post_type'])?$instance['post_type']:'post';
$list_filter = isset($instance['filter'])?$instance['filter']:'{}';
$list_display = isset($instance['display'])?$instance['display']:5;
$list_channel = isset($instance['channel'])?$instance['channel']:0;
$list_division = isset($instance['division'])?$instance['division']:0;
$readmore = isset($instance['readmore'])?$instance['readmore'] : '';
$list_args1 = array( "post_type" => "any", "post__in" => get_post_meta($instance['storylist_id_1'], 'storylist', true), "orderby" => "post__in" );
$posts1 = new WP_Query();
$posts1 = $posts1->query($list_args1);
$list_args2 = array( "post_type" => "any", "post__in" => get_post_meta($instance['storylist_id_2'], 'storylist', true), "orderby" => "post__in" );
$posts2 = new WP_Query();
$posts2 = $posts2->query($list_args2);
// Note: posts temporarily rendered with ajax
echo $args['before_widget'];
$instance['tab_2_title'] = get_the_title($instance['storylist_id_2']);
//#TODO: Use get_template_part('content/post', $modifier); on tabs too.
?>
<div class="module tabs">
<div class="striped striped-gray">
<!-- Nav tabs -->
<ul class="nav nav-tabs nav-justified" role="tablist">
<li class="active">
<a href="#tab-pane-1" role="tab" data-toggle="tab">
<h2 class="h4"><?= $instance['tab_1_title'] ?></h2>
</a>
</li>
<li>
<a href="#tab-pane-2" role="tab" data-toggle="tab">
<h2 class="h4"><?= $instance['tab_2_title'] ?></h2>
</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="tab-pane-1">
<div class="post-list no-c-paginator" max="<?= $instance['n'] ?>">
<?php
$n = 0;
foreach((array)$posts1 as $post): setup_postdata($post);
$n++;
if ( $n % 3 == 1) {
?> <div class="no-c-container<?php echo $n == 1 ? ' active' : '';?>"> <?php
}
?>
<article class="article thumblist no-c-paginator-item">
<!-- thumbnail -->
<?php echo the_post_thumbnail('cm_thumb', array('class' => 'img-thumbnail pull-left', 'style' => 'margin-right: 0.5em;')) ?>
<header>
<!-- terms -->
<?php if (!empty($terms) ): ?>
<p class="terms">
<?= $terms[0]['name'] ?>
</p>
<?php endif; ?>
<!-- title -->
<h3 class="title"><?php echo apply_filters('the_title', the_title()); ?></h3>
<!-- Time -->
<div class="date-author">
<?php include(locate_template('UI/byline.php')); ?>
<span class="topic"><?php echo cm_get_single_topic() ?></span>
</div>
</header>
<div class="clearfix"></div><!-- to clear the thumbnail's left floating -->
</article>
<?php
if ( $n % 3 == 0) {
?> </div> <?php
}
endforeach; wp_reset_postdata();
if ( $n % 3 != 0) {
?> </div> <?php
}
?>
<?php if($readmore): ?>
<div class="actions">
<button href="<?php echo $readmore; ?>" class="btn btn-primary btn-xs">View More</button>
</div>
<?php endif; ?>
</div>
<div class="actions">
<button class="btn btn-primary prev-item" disabled="disabled"><i class="fa fa-chevron-circle-left"></i> Prev</button>
<button class="btn btn-primary next-item">Next <i class="fa fa-chevron-circle-right"></i></button>
</div>
</div>
<div class="tab-pane" id="tab-pane-2">
<div class="post-list no-c-paginator" max="<?= $instance['n'] ?>">
<?php
$n = 0;
foreach((array)$posts2 as $post):
$n++;
if ( $n % 3 == 1) {
?> <div class="no-c-container<?php echo $n == 1 ? ' active' : '';?> "> <?php
}
?>
<article class="article thumblist no-c-paginator-item">
<!-- thumbnail -->
<?php echo get_the_post_thumbnail($post->ID, 'cm_thumb', array('class' => 'img-thumbnail pull-left', 'style' => 'margin-right: 0.5em;')) ?>
<header>
<!-- terms -->
<?php if (!empty($terms) ): ?>
<p class="terms">
<?= $terms[0]['name'] ?>
</p>
<?php endif; ?>
<!-- title -->
<h3 class="title"><?php echo apply_filters('the_title', $post->post_title); ?></h3>
<!-- Time -->
<div class="date-author">
<time datetime="<?php the_time('c'); ?>" pubdate="pubdate" ><?php the_time('F j, Y'); ?></time>
<?php include(locate_template('UI/byline.php')); ?>
<span class="topic"><?php echo cm_get_single_topic() ?></span>
</div>
</header>
<div class="clearfix"></div><!-- to clear the thumbnail's left floating -->
</article>
<?php
if ( $n % 3 == 0) {
?> </div> <?php
}
endforeach;
if ( $n % 3 != 0) {
?> </div> <?php
}
?>
<?php //if($readmore): ?>
<div class="actions">
View More
</div>
<?php //endif; ?>
<!--<div class="actions">
<button class="btn btn-primary prev-item" disabled="disabled"><i class="fa fa-chevron-circle-left"></i> Prev</button>
<button class="btn btn-primary next-item">Next <i class="fa fa-chevron-circle-right"></i></button>
</div>-->
</div>
</div>
</div>
</div>
</div>
<?php
echo $args['after_widget'];
}
public function form( $instance ) {
$instance['tab_1_title'] = isset($instance['tab_1_title'])?$instance['tab_1_title']:'Tab 1';
$instance['tab_2_title'] = isset($instance['tab_2_title'])?$instance['tab_2_title']:'Tab 2';
$instance['n'] = isset($instance['n'])?$instance['n']:4;
$sl_posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'storylist'
));
?>
<h5>Tab 1</h5>
<p>
<label for="<?php echo $this->get_field_id( 'tab_1_title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'tab_1_title' ); ?>" name="<?php echo $this->get_field_name( 'tab_1_title' ); ?>" type="text" value="<?php echo esc_attr( $instance['tab_1_title'] ); ?>">
</p>
<p>
<label for="<?php echo $this->get_field_id( 'storylist_id_1' ); ?>"><?php _e( 'Story List:' ); ?></label>
<select id="<?php echo $this->get_field_id( 'storylist_id_1' ); ?>" name="<?php echo $this->get_field_name( 'storylist_id_1' ); ?>">
<?php
if (count($sl_posts)) {
foreach($sl_posts as $storyList) {
$selected = ($instance['storylist_id_1'] == $storyList->ID ? "selected='selected'" : "");
echo "<option value='{$storyList->ID}' {$selected}>{$storyList->post_title}</option>";
}
} else {
echo "<option value='0'>"._('No Story Lists Found')."</option>";
}
?>
</select>
</p>
<!-- Number of items to show -->
<p>
<label for="<?php echo $this->get_field_id( 'n' ); ?>"><?php _e( 'Number of items to show at once:' ); ?></label>
<input id="<?php echo $this->get_field_id( 'n' ); ?>" name="<?php echo $this->get_field_name( 'n' ); ?>" type="number" min="0" step="1" value="<?php echo intval($instance['n']) ?>">
</p>
<h5>Tab 2</h5>
<p>
<label for="<?php echo $this->get_field_id( 'tab_2_title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'tab_2_title' ); ?>" name="<?php echo $this->get_field_name( 'tab_2_title' ); ?>" type="text" value="<?php echo esc_attr( $instance['tab_2_title'] ); ?>">
</p>
<p>
<label for="<?php echo $this->get_field_id( 'storylist_id_2' ); ?>"><?php _e( 'Story List:' ); ?></label>
<select id="<?php echo $this->get_field_id( 'storylist_id_2' ); ?>" name="<?php echo $this->get_field_name( 'storylist_id_2' ); ?>">
<?php
if (count($sl_posts)) {
foreach($sl_posts as $storyList) {
$selected = ($instance['storylist_id_2'] == $storyList->ID ? "selected='selected'" : "");
echo "<option value='{$storyList->ID}' {$selected}>{$storyList->post_title}</option>";
}
} else {
echo "<option value='0'>"._('No Story Lists Found')."</option>";
}
?>
</select>
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['tab_1_title'] = isset($new_instance['tab_1_title'])?$new_instance['tab_1_title']:'Tab 1';
$instance['tab_2_title'] = isset($new_instance['tab_2_title'])?$new_instance['tab_2_title']:'Tab 2';
$instance['storylist_id_1'] = isset($new_instance['storylist_id_1']) ? (int)$new_instance['storylist_id_1'] : 0;
$instance['storylist_id_2'] = isset($new_instance['storylist_id_2']) ? (int)$new_instance['storylist_id_2'] : 0;
$instance['n'] = isset($new_instance['n']) ? (int)$new_instance['n'] : 4;
return $instance;
}
}
add_action( 'widgets_init', function(){ register_widget( 'ChemTabs' ); });
I created a page template specifically for this page, but it just comes up blank. Here is the code for that page:
<?php
/*
Template Name: Custom StoryList Archives
*/
?>
<?php get_header(); ?>
<?php
if ( is_single(210639) ) {
$args = array( 'post_type' => 'storylist', 'posts_per_page' => 30 );
}
endif();
?>
<?php get_footer(); ?>
What am I missing????
I solved this by adding this code: $list_args2 = array( "post_type" => "any", "post__in" => get_post_meta( 210639, 'storylist', true), "orderby" => "post__in", 'post_status' => 'publish' );
I have this custom loop and for some reason the "Sort" isn't working.
<?php
if(isset($_REQUEST['sort'])){
if($_REQUEST['sort'] == 'newest' )
$order = "&orderby=title&order=DESC";
else if($_REQUEST['sort'] == 'oldest' )
$order = "&orderby=title&order=ASC";
else if($_REQUEST['views'] == 'oldest' )
$order = "&meta_key=views&orderby=meta_value_num&order=DESC";
}
else
$order = "&orderby=ID&order=DESC";
?>
<form method="post" id="order">
<select name="sort" onchange='this.form.submit()'>
<option value="newest">Sort by Newest</option>
<option value="oldest">Sort by Oldest</option>
<option value="views">Sort by Most Viewed</option>
</select>
</form>
<ul class="acapellas row">
<?php
$loop = new WP_Query( array(
'post_type' => 'acapella',
'posts_per_page' => 10,
'paged' => $paged,
'orderby' => 'date',
'order' => $_POST['sort']
) );
?>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $posts = query_posts($query_string . $order); ?>
<li class="post-<?php the_ID(); ?> col-md-6">
<div class="wrap">
<h2><?php the_title() ?></h2>
<?php if(pmpro_hasMembershipLevel($level_id)) { ?>
<?php the_content(); ?>
<?php } else { ?>
<div class="pro-player">
<div class="upgrade">
<a href="<?php bloginfo('url'); ?>/pro" >Upgrade to unlock</a>
</div>
</div>
<?php } ?>
<a class="download left" href="<?php the_permalink(); ?>">Download</a>
<span class="list-date right">First added: <?php the_time('F jS, Y') ?></span><br>
<?php
global $post;
$post_type = get_post_type(get_the_ID());
$post_type_taxonomies = get_object_taxonomies($post_type);
if (!empty($post_type_taxonomies)) {
echo '<ul class="details">';
foreach ($post_type_taxonomies as $taxonomy) {
$terms = get_the_term_list(get_the_ID(), $taxonomy, '', '</li><li>', '');
if ($terms) {
echo '<li>' . $terms . '</li>';
}
}
echo '</ul>';
}
?>
</div>
</li>
<?php endwhile; endif; ?>
</ul>
You can use function get_posts().
$posts = get_posts([
'orderby' => 'date',
'order' => $_POST['sort']
]);
And send post variable 'ASC' or 'DESC' - that will be the newest or oldest
My widget is showingmin my admin area but when I click it so that it can drop down so that I may enter information... it only shows the DELETE link, CLOSE link and SAVE button. the widget will not expand. I believe I am missing something in the script for the textarea causing the widget not to function properly.
<?php
if( !class_exists('smWidget') ):
class smWidget extends WP_Widget {
// constructor
function smWidget() {
// Give widget name here
$widget_ops = array('description' => __('Displays a selected post from a selected post type.', 'ci_theme'));
parent::WP_Widget('smWidget', $name='-= SM Item =-', $widget_ops);
}
// display widget
function widget($args, $instance) {
extract( $args );
$ci_post_id = $instance['postid'];
$post_type_name = $instance['post_type_name'];
if( empty($ci_post_id) or empty($post_type_name) )
return;
$q = new WP_Query( array(
'post_type' => $post_type_name,
'p' => $ci_post_id
) );
echo $before_widget;
$title = apply_filters( 'widget_title', empty( $instance['title']) ? '' : $instance['title'], $instance, $this->id_base );
if ($title)
echo $before_title . $title . $after_title;
while ( $q->have_posts() ): $q->the_post();
global $post;
if ( get_post_type() == 'testimonial' ) :
?>
<div class="testimonial-wrap">
<div class="testimonial-inner">
<blockquote> <i class="fa fa-quote-left"></i>
<?php the_content(); ?>
<cite>
<?php the_title(); ?>
</cite> </blockquote>
</div>
</div>
<?php
elseif ( get_post_type() == 'video' ) :
?>
<div <?php post_class('item'); ?>>
<?php
$video = get_post_meta($post->ID, 'ci_cpt_video_url', true);
echo wp_oembed_get($video);
?>
</div>
<?php
else :
get_template_part('loop', 'item');
endif;
endwhile;
wp_reset_postdata();
echo $after_widget;
}
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = sanitize_text_field($new_instance['title']);
$instance['post_type_name'] = sanitize_key($new_instance['post_type_name']);
$instance['postid'] = absint($new_instance['postid']);
$instance['teatarea'] = absint($new_instance['textarea']);
return $instance;
}
function form($instance){
$defaults = array(
'title' => '',
'post_type_name' => 'post',
'postid' => '',
'textarea' => '',
);
$instance = wp_parse_args( (array) $instance, $defaults );
$title = $instance['title'];
$post_type_name = $instance['post_type_name'];
$post_id = $instance['postid'];
$textarea = $instance['textarea'];
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">
<?php _e('Title (optional):', 'ci_theme'); ?>
</label>
<input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" class="widefat" />
</p>
<?php
$post_types = get_post_types( array('public' => true), 'objects' );
unset($post_types['attachment'], $post_types['slider']);
?>
<p>
<label for="<?php echo $this->get_field_id('post_type_name'); ?>">
<?php _e('Show posts from this post type:', 'ci_theme'); ?>
<label>
</p>
<?php ?>
<select name="<?php echo $this->get_field_name('post_type_name'); ?>" id="<?php echo $this->get_field_id('post_type_name'); ?>" >
<?php
foreach( $post_types as $key => $pt )
{
?>
<option value="<?php echo esc_attr($key); ?>" <?php selected($key, $post_type_name); ?>><?php echo $pt->labels->name; ?></option>
<?php
}
?>
</select>
<img src="<?php echo get_child_or_parent_file_uri('/panel/img/ajax-loader-16x16.gif'); ?>" class="loading_posts" style="display: none;">
<?php
?>
<p></p>
<?php
?>
<p>
<label for="<?php echo $this->get_field_id('postid'); ?>">
<?php _e('Select a post to show:', 'ci_theme'); ?>
</label>
</p>
<?php
?>
<p class="ci_widget_post_type_posts_dropdown">
<?php
wp_dropdown_posts(
array(
'post_type' => $post_type_name,
'show_option_none' => ' ',
'selected' => $post_id,
'class' => 'widefat'
),
$this->get_field_name('postid')
);
?>
</p>
<?php
?>
<p>
<label for="<?php echo $this->get_field_id('textarea'); ?>">
<?php _e('Description:', 'ci_theme'); ?>
</label>
<textarea class="widefat" id="<?php echo $this->get_field_id('textarea'); ?>" name="<?php echo $this->get_field_name('textarea'); ?>" rows="7" cols="20" ><?php echo $textarea; ?></textarea>
</p>
<?php
}
static function _ajax_get_posts()
{
$post_type_name = sanitize_key($_POST['post_type_name']);
$name_field = esc_attr($_POST['name_field']);
$str = wp_dropdown_posts(
array(
'echo' => false,
'post_type' => $post_type_name,
'show_option_none' => ' ',
'class' => 'widefat'
),
$name_field
);
echo $str;
die;
}
} // class
register_widget('smWidget');
add_action('wp_ajax_ci_widget_post_type_ajax_get_posts', 'smWidget::_ajax_get_posts');
endif; // !class_exists
?>
I'm currently building a site which is based on the templatic events v2 theme. I have done some customization which is working fine, but this one is kind of out of my reach.
The problem is as following.
I need to build a widget which only outputs the events (custom posts) that are tagged as featured. Right now I have got some different ways of showing events, but they are pretty much just sorted by category or by date.
example site: http://www.blaest.no/jonnysnorkel
Here is a the current code for my widget the widget I'm working on:
class blaestfeatured extends WP_Widget {
function blaestfeatured() {
//Constructor
$widget_ops = array('classname' => 'widget category List View', 'description' => 'Custom Featured event widget by Christoffer Sandstrøm' );
$this->WP_Widget('blaestfeatured', 'blaestfeatured', $widget_ops);
}
function widget($args, $instance) {
// prints the widget
extract($args, EXTR_SKIP);
echo $before_widget;
$widget_id= $args['widget_id'];
$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
$category = empty($instance['category']) ? '' : apply_filters('widget_category', $instance['category']);
$post_number = empty($instance['post_number']) ? '5' : apply_filters('widget_post_number', $instance['post_number']);
$post_link = empty($instance['post_link']) ? '' : apply_filters('widget_post_link', $instance['post_link']);
$more_link = empty($instance['more_link']) ? '' : apply_filters('widget_more_link', $instance['more_link']);
$character_cout = empty($instance['character_cout']) ? '15' : apply_filters('widget_character_cout', $instance['character_cout']);
$sorting = empty($instance['event_sorting']) ? 'Latest Published' : apply_filters('widget_event_sorting', $instance['event_sorting']);
?>
<h3 class=""><?php echo $title; ?> </h3>
<ul>
<?php //$type = get_option('ptthemes_event_sorting');
if ( $sorting != '' )
{
global $wpdb;
if ( $sorting == 'Random' )
{
$orderby = "(select $wpdb->postmeta.meta_value from $wpdb->postmeta where $wpdb->postmeta.post_id = p.ID and $wpdb->postmeta.meta_key like \"st_date\") ASC, rand()";
}
elseif ( $sorting == 'Alphabetical' )
{
$orderby = "p.post_title ASC";
}elseif($sorting =='s_date'){
$today = date('Y-m-d');
$orderby = "(select $wpdb->postmeta.meta_value from $wpdb->postmeta where $wpdb->postmeta.post_id = p.ID and $wpdb->postmeta.meta_key like \"st_date\") ASC";
}
else
{
$orderby = "(select $wpdb->postmeta.meta_value from $wpdb->postmeta where $wpdb->postmeta.post_id=p.ID and $wpdb->postmeta.meta_key = 'featured_h') ASC, p.post_date DESC";
}
}
?>
<?php
global $post,$wpdb;
if($category)
{
$category = "'".str_replace(",","','",$category)."'";
$sqlsql = " and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($category) )";
}
$today = date('Y-m-d');
if ( false === ( $latest_menus = get_transient( 'onecolumnslist'.$widget_id ) ) ) {
// It wasn't there, so regenerate the data and save the transient
$where = "AND p.ID in (select $wpdb->postmeta.post_id from $wpdb->postmeta where $wpdb->postmeta.meta_key='end_date' and date_format($wpdb->postmeta.meta_value,'%Y-%m-%d')>='".$today."') ";
#$sql = "select p.* from $wpdb->posts p where p.post_type='".CUSTOM_POST_TYPE1."' and (p.post_status='publish' or p.post_status='recurring' ) AND (p.ID in ( select $wpdb->postmeta.post_id from $wpdb->postmeta where $wpdb->postmeta.meta_key='event_type' and $wpdb->postmeta.meta_value ='Regular event')) $sqlsql $where order by $orderby limit $post_number";
$latest_menus = $wpdb->get_results($sql);
set_transient( 'onecolumnslist'.$widget_id, $latest_menus, 60*60*12 );
}
$pcount=0;
if($latest_menus)
{
foreach($latest_menus as $post) :
setup_postdata($post);
$pcount++; ?>
<?php
$is_parent = $post->post_parent;
if($is_parent)
$post_id = $post->post_parent;
else
$post_id = $post->ID;
$post_images = bdw_get_images_with_info($post_id,'thumb');
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ) , 'single-post-thumbnail' );
if($image[0] != '')
$thumb = $image[0];
elseif($post_images[0]['file'] != '')
$thumb = $post_images[0]['file']; ?>
<?php
$terms = get_the_terms( $post->ID, 'eventcategory' ); // Definerer måten å hente cssclassen for terms.
if ( $terms && ! is_wp_error( $terms ) ) :
$classcategory = array();
foreach ( $terms as $term ) {
$classcategory[] = $term->name;
}
$postclasscategory = join( ", ", $classcategory );
?>
<?php
$args = array(
'post_type' => 'event',
'meta_query' => array(
array(
'key' => 'featured_h',
'value' => 'h',
)
)
);
$query = new WP_Query($args);
while( $query->have_posts() ) : $query->the_post(); ?>
<li id="post-<?php the_ID(); ?>" <?php get_post_class(); ?> ><?php } ?>
<h3 class="<?php echo $postclasscategory; ?>" > <?php echo get_formated_date(get_post_meta($post->ID,'st_date',true));?> </h3>
<div class="eventcontainer">
<?php if(get_post_meta($post->ID,'featured_h',true) == 'h' ) { ?><div class="featured_img_s"></div><?php }?>
<?php if ( $thumb != '' ) { ?>
<a class="headliner-img" href="<?php the_permalink(); ?>">
<img src="<?php echo $thumb; ?>" width="290" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
<?php
} else { ?>
<img src="<?php echo get_template_directory_uri()."/images/no-image.png"; ?>" height="120" alt="<?php echo #$post_img[0]['alt']; ?>" />
</div>
<?php endwhile; ?>
<h3 id="post-<?php the_ID(); ?>"> <?php the_title(); ?></h3>
</li> <!-- -->
<?php endforeach; ?>
<?php }else{ ?>
<p><?php _e('Not a single Event is there','templatic');?></p>
<?php } ?>
<?php
echo '</ul>';
echo $after_widget;
}
function update($new_instance, $old_instance) {
//save the widget
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['category'] = strip_tags($new_instance['category']);
$instance['post_number'] = strip_tags($new_instance['post_number']);
$instance['post_link'] = strip_tags($new_instance['post_link']);
$instance['more_link'] = strip_tags($new_instance['more_link']);
$instance['character_cout'] = strip_tags($new_instance['character_cout']);
$instance['event_sorting'] = strip_tags($new_instance['event_sorting']);
return $instance;
}
function form($instance) {
//widgetform in backend
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'category' => '', 'post_number' => '','character_cout' => '','more_link' => '', 'event_sorting' => 'Latest Published' ) );
$title = strip_tags($instance['title']);
$category = strip_tags($instance['category']);
$post_number = strip_tags($instance['post_number']);
$post_link = strip_tags($instance['post_link']);
$more_link = strip_tags($instance['more_link']);
$character_cout = strip_tags($instance['character_cout']);
$sorting = strip_tags($instance['event_sorting']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php echo TITLE_TEXT; ?>:
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('category'); ?>"><?php echo CATEGORY_IDS_TEXT; ?>:
<input class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" type="text" value="<?php echo esc_attr($category); ?>" />
</label> <p><?php echo fetch_categories_ids('eventcategory'); ?></p>
</p>
<p>
<label for="<?php echo $this->get_field_id('post_number'); ?>"><?php echo NUMBER_POSTS_TEXT; ?>:
<input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>" name="<?php echo $this->get_field_name('post_number'); ?>" type="text" value="<?php echo esc_attr($post_number); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('event_sorting'); ?>"><?php echo SORT_EVENT; ?>:
<select name="<?php echo $this->get_field_name('event_sorting'); ?>" id="<?php echo $this->get_field_id('event_sorting'); ?>">
<option selected="selected" value="Latest Published"><?php _e('Latest Published','templatic'); ?></option>
<option <?php if ($sorting == 'Random') { echo 'selected=selected'; } ?> value="Random"><?php _e('Random','templatic'); ?></option>
<option <?php if ($sorting == 'Alphabetical') { echo 'selected=selected'; } ?> value="Alphabetical"><?php _e('Alphabetical','templatic'); ?></option>
<option <?php if ($sorting == 's_date') { echo 'selected=selected'; } ?> value="s_date"><?php _e('As Per Start Date','templatic'); ?></option>
</select>
</label>
</p>
<?php
}
}
register_widget('blaestfeatured');
// BLAEST FEATURED ENDS
?>
I've tried a couple of nights for myself, but unfortunately my PHP skills are lackluster at best.
Edit: Updated with whole widget code.
Here is your query:
$args = array(
'post_type' => 'my_custom_post_type',
'posts_per_page' => 10,
'meta_query' => array(
array(
'key' => 'featured_h',
'value' => 'h',
)
)
);
$query = new WP_Query($args);
while( $query->have_posts() ) : $query->the_post(); ?>
<li id="post-<?php the_ID(); ?>" <?php get_post_class(); ?> ><?php } ?>
<h3 class="<?php echo $postclasscategory; ?>" > <?php echo get_formated_date(get_post_meta($post->ID,'st_date',true));?> </h3>
<div class="eventcontainer">
<?php if(get_post_meta($post->ID,'featured_h',true) == 'h' ) { ?><div class="featured_img_s"></div><?php }?>
<?php if ( $thumb != '' ) { ?>
<a class="headliner-img" href="<?php the_permalink(); ?>">
<img src="<?php echo $thumb; ?>" width="290" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a>
<?php
} else { ?>
<img src="<?php echo get_template_directory_uri()."/images/no-image.png"; ?>" height="120" alt="<?php echo #$post_img[0]['alt']; ?>" />
</div>
<?php endwhile; ?>