Current Year Post type Wordpress - php

I've a this query post
<?php
$args = (array(
'post_type' => 'issue_number',
'posts_per_page' => 13,
'paged' => $paged
));
// query
$the_query = new WP_Query( $args );
?>
<?php while( $the_query->have_posts() ) : $the_query->the_post();?>
bla bla
<?php endwhile; ?>
I want to display only current year post type (issue_number)...how to do?

This should do it.
$current_year = the_date( 'Y' );
$args = array(
'post_type' => 'issue_number',
'posts_per_page' => 13,
'paged' => $paged,
'year' => $current_year
);

Related

How do I add an echo inside an array?

I'm trying to show products from a certain category on a page like his:
$args = array( 'post_type' => 'product', 'posts_per_page' => 5, 'product_cat' => 'prcategory1', 'orderby' => 'price');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
This one works. However, I'd like 'prcategory1' to be taken from a custom field of the page. Something like this (incorrect code incoming):
$args = array( 'post_type' => 'product', 'posts_per_page' => 5, 'product_cat' => 'get_post_meta(get_the_ID(), 'custom_cat_name', TRUE); ?>', 'orderby' => 'price');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
There is some errors in your code, try this for your array :
$args = array(
'post_type' => 'product',
'posts_per_page' => 5,
'product_cat' => get_post_meta(
get_the_ID(),
'custom_cat_name',
TRUE
),
'orderby' => 'price'
)

How to retrive tag value and set tag value to array in wordpress php

I want to retrieve tag value and set it to array.Here i retrieve the value but,how can i set that tag value to below array.I want to do without Plugin.
<?php
$args = array( 'post_type' => 'campaign', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
$pps=apply_filters('campaign_tag', get_post_meta($post->ID, 'campaign_tag', true));
echo $pps;
echo '</div>';
endwhile;
$type = 'post';
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 10,
'ignore_sticky_posts'=> 1,
'tag' => '',
'paged' => $paged
);
?>

How can I show the tags for each post in the result of my query - WP

I have the following query:
$recent_posts = wp_get_recent_posts(array(
'post_type' => 'post',
'post','numberposts' => 9,
'post_status' => 'publish'
foreach($recent_posts as $post1) { $j++
and print the result in a html table.
echo $post1['post_title'];
echo $post1['post_content'];
but not how to display the tags associated with post
If You know the post_id You can use:
wp_get_post_tags( $post_id, $args )
More here: https://codex.wordpress.org/Function_Reference/wp_get_post_tags
i can use
the_title();
get_the_content();
the_tags('Tags: ',','); etc
previously declared:
$temp_query = $wp_query;
$args = array(
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'numberposts' => 9,
'post_status' => 'publish'
);
query_posts( $args );
if (have_posts())
while ( have_posts() ) : the_post();

PHP: Doing while loop if "if" statement is true

I am trying to show only those events, which are in current date or in future. To show events I have such code:
<?php
$wp_query = new WP_Query();
global $more;
// set $more to 0 in order to only get the first part of the post
$more = 0;
$wp_query->query( array( 'post_type' => 'events', 'posts_per_page' => 7, 'paged' => $paged, 'orderby' => 'menu_order', 'order' => 'ASC') );
while ( ($wp_query->have_posts()) ): $wp_query->the_post();
get_template_part( 'content', 'event' );
endwhile;
?>
I tried to add "IF statement" to compare event start date with current date, but it doesn't seem to work. I have tried a lots of versions, but this one I think should work:
$wp_query->query( array( 'post_type' => 'events', 'posts_per_page' => 7, 'paged' => $paged, 'orderby' => 'menu_order', 'order' => 'ASC') );
$OstartDate = get_post_meta($post->ID, '_event_start', TRUE);
$today = date('d.m.Y');
while ( ($wp_query->have_posts()) && ($OstarDate < $today) ):
$wp_query->the_post();
From the second one you should try,
$OstartDate=get_post_meta($post->ID,'_event_start',TRUE);//check it will return a number
if(time() > $OstartDate)
{
while ($wp_query->have_posts()):
$wp_query->the_post();
.....
}
a7-simple-events may help you.
You can compare the posts with postmeta using meta_query
$today = date('d.m.Y');
$args=array( 'post_type' => 'events', 'posts_per_page' => 7, 'paged' => $paged, 'orderby' => 'menu_order', 'order' => 'ASC', 'meta_query' => array(
array(
'key' => '_event_start',
'value' => $today,
'type' => 'date',
'compare' => '<'
)
)) ;
$wp_query = new WP_Query( $args );
while ( ($wp_query->have_posts()) ):
$wp_query->the_post();
endwhile;

How can I skip the first post in WordPress?

How can I skip the first post in WordPress?
<?php
$recentPosts = new WP_Query();
$recentPosts->query(array('showposts' => 6,'post_type' =>array('stiri')));
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
Use the offset parameter:
<?php
$recentPosts = new WP_Query( 'offset=1' ) );
$recentPosts->query(array('showposts' => 6,'post_type' =>array('stiri')));
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
Use the offset
$recentPosts = new WP_Query (
array(
'post_type' => 'stiri',
'post_status' => 'publish',
'posts_per_page' => 6, // all = -1
'orderby' => 'date',
'order' => 'DESC',
'offset' => 1
)
);

Categories