add_shortcode('portfolio', 'my_shortcode_function');
function my_shortcode_function() {
$wp_query = new WP_Query( [
'post_type' => 'portfolio',
'posts_per_page' => 6,
'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1
] );
ob_start();
echo '<div class="portfolio">';
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : $wp_query->the_post();
get_template_part( 'template-parts/portfolio', get_post_format() );
endwhile;
else :
get_template_part( 'template-parts/content', 'none' );
endif;
echo '</div>';
posts_nav_link();
$out = ob_get_clean();
return $out;
}
$options = array(
'post_type' => $args['type'],
'posts_per_page' => $args['posts'],
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
'feature_clause' => array(
'key' => 'event_date_news',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'event_date_news' => 'ASC',
'date' => 'DESC',
)
);
add_shortcode( 'home-slides', 'lvl_home_post_slides' );
function lvl_home_post_slides( $atts ) {
ob_start();
$args = shortcode_atts( array (
'type' => 'post',
// 'order' => 'date',
// 'orderby' => 'title',
'posts' => 10,
'post_status' => 'publish',
'public' => true,
), $atts );
$options = array(
'post_type' => $args['type'],
'posts_per_page' => $args['posts'],
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
'query_one' => array('key' => 'post_date'),
'query_two' => array('key' => 'event_date'),
),
'orderby' => array(
'query_one' => 'DESC',
'query_two' => 'ASC',
),
);
// https://toster.ru/q/687409
$query = new WP_Query( $options );
if ( $query->have_posts() ) { ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php
get_template_part( 'template-parts/slides', get_post_format() );
?>
<?php endwhile;
wp_reset_postdata(); ?>
<?php $myvariable = ob_get_clean();
return $myvariable;
}
}
add_shortcode( 'home-slides', 'lvl_home_post_slides' );
function lvl_home_post_slides( $atts ) {
ob_start();
$args = shortcode_atts( array (
'type' => 'post',
'posts' => 10,
'public' => true,
), $atts );
$options = array(
'post_type' => $args['type'],
'posts_per_page' => $args['posts'],
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'event_date'
);
$query = new WP_Query( $options );
if ( $query->have_posts() ) { ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php
get_template_part( 'template-parts/slides', get_post_format() );
?>
<?php endwhile;
wp_reset_postdata(); ?>
<?php $myvariable = ob_get_clean();
return $myvariable;
}
}