global $post; // не обязательно
$myposts = get_posts( array(
'post_type' => 'post'
) );
foreach( $myposts as $post ) :
setup_postdata( $post );
echo '<div class="column">';
?>
<div class="col-wrap">
<?php
if ( has_post_thumbnail() ) : ?>
<div class="thumbnail">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<?php endif; ?>
<div class="meta-info">
<div class="meta-align">
<div class="tags">
<?php the_tags( '', ' ' ); ?>
</div>
<div class="title">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="author-date">
<span class="author">
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo esc_html( get_the_author() ); ?></a>
<span>-</span>
</span>
<span class="date"><?php echo esc_html( the_time( get_option( 'date_format' ) ) ); ?></span>
</div>
</div>
</div>
</div>
<?php
echo '</div>';
endforeach;
wp_reset_postdata(); // сбрасываем переменную $post
Впрочем, попробуйте задампить $args перед самим new WP_Query, посмотрите что там ему передается в итоге
array(4) {
["posts_per_page"]=>
string(1) "4"
["post_type"]=>
string(4) "post"
["ignore_sticky_posts"]=>
bool(true)
["no_found_rows"]=>
bool(true)
}
Ну и потом после инициализации сам WP_Query задампите и посмотрите что там прилетело.
object(WP_Query)#1216 (50) {
["query"]=>
array(4) {
["posts_per_page"]=>
string(1) "4"
["post_type"]=>
string(4) "post"
["ignore_sticky_posts"]=>
bool(true)
["no_found_rows"]=>
bool(true)
}
["query_vars"]=>
array(64) {
["posts_per_page"]=>
int(4)
["post_type"]=>
string(4) "post"
["ignore_sticky_posts"]=>
bool(true)
["no_found_rows"]=>
bool(true)
["error"]=>
string(0) ""
["m"]=>
string(0) ""
["p"]=>
int(0)
["post_parent"]=>
string(0) ""
["subpost"]=>
string(0) ""
["subpost_id"]=>
string(0) ""
["attachment"]=>
string(0) ""
["attachment_id"]=>
int(0)
["name"]=>
string(0) ""
["static"]=>
string(0) ""
["pagename"]=>
string(0) ""
["page_id"]=>
int(0)
["second"]=>
string(0) ""
["minute"]=>
string(0) ""
["hour"]=>
string(0) ""
["day"]=>
int(0)
["monthnum"]=>
int(0)
["year"]=>
int(0)
["w"]=>
int(0)
["category_name"]=>
string(0) ""
["tag"]=>
string(0) ""
["cat"]=>
string(0) ""
["tag_id"]=>
string(0) ""
["author"]=>
string(0) ""
["author_name"]=>
string(0) ""
["feed"]=>
string(0) ""
["tb"]=>
string(0) ""
["paged"]=>
int(0)
["meta_key"]=>
string(0) ""
["meta_value"]=>
string(0) ""
["preview"]=>
string(0) ""
["s"]=>
string(0) ""
["sentence"]=>
string(0) ""
["title"]=>
string(0) ""
["fields"]=>
string(0) ""
["menu_order"]=>
string(0) ""
["embed"]=>
string(0) ""
["category__in"]=>
array(0) {
}
["category__not_in"]=>
array(0) {
}
["category__and"]=>
array(0) {
}
["post__in"]=>
array(0) {
}
["post__not_in"]=>
array(0) {
}
["post_name__in"]=>
array(0) {
}
["tag__in"]=>
array(0) {
}
["tag__not_in"]=>
array(0) {
}
["tag__and"]=>
array(0) {
}
["tag_slug__in"]=>
array(0) {
}
["tag_slug__and"]=>
array(0) {
}
["post_parent__in"]=>
array(0) {
}
["post_parent__not_in"]=>
array(0) {
}
["author__in"]=>
array(0) {
}
["author__not_in"]=>
array(0) {
}
["suppress_filters"]=>
bool(false)
["cache_results"]=>
bool(true)
["update_post_term_cache"]=>
bool(true)
["lazy_load_term_meta"]=>
bool(true)
["update_post_meta_cache"]=>
bool(true)
["nopaging"]=>
bool(false)
["comments_per_page"]=>
string(2) "50"
["order"]=>
string(4) "DESC"
}
["tax_query"]=>
object(WP_Tax_Query)#1275 (6) {
["queries"]=>
array(0) {
}
["relation"]=>
string(3) "AND"
["table_aliases":protected]=>
array(0) {
}
["queried_terms"]=>
array(0) {
}
["primary_table"]=>
string(8) "wp_posts"
["primary_id_column"]=>
string(2) "ID"
}
["meta_query"]=>
object(WP_Meta_Query)#1209 (9) {
["queries"]=>
array(0) {
}
["relation"]=>
NULL
["meta_table"]=>
NULL
["meta_id_column"]=>
NULL
["primary_table"]=>
NULL
["primary_id_column"]=>
NULL
["table_aliases":protected]=>
array(0) {
}
["clauses":protected]=>
array(0) {
}
["has_or_relation":protected]=>
bool(false)
}
["date_query"]=>
bool(false)
["request"]=>
string(198) "SELECT wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 4"
["posts"]=>
array(4) {
[0]=>
object(WP_Post)#1218 (24) {
["ID"]=>
int(139)
["post_author"]=>
string(1) "1"
["post_date"]=>
string(19) "2019-07-13 10:24:04"
["post_date_gmt"]=>
string(19) "2019-07-13 10:24:04"
["post_content"]=>
string(2316) "
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium, tortor vitae porttitor suscipit, sapien purus aliquet risus, eu finibus arcu ante nec risus. Mauris porta a massa sed consectetur. Fusce porta, quam sit amet tincidunt facilisis, ipsum enim semper nunc, ut sodales ipsum lectus eget dolor. Duis non dapibus elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec vel leo egestas, finibus felis ac, luctus felis. Nunc mattis elementum ullamcorper. Vivamus eros mi, dapibus sed enim quis, ullamcorper eleifend nunc. Pellentesque ex eros, venenatis in enim nec, facilisis tincidunt sapien. Quisque porttitor, urna a venenatis eleifend, lacus leo tempus elit, et rutrum nisi libero pulvinar ante. Vestibulum faucibus odio eget tellus maximus vestibulum. In eget eros et massa blandit sagittis. Nullam hendrerit, metus eget varius scelerisque, nisl urna venenatis odio, pharetra pharetra lectus justo aliquet quam.
Integer ac metus mi. Etiam eget arcu quis ligula ullamcorper hendrerit nec at neque. Vestibulum sed mauris tincidunt, tristique tellus sed, fermentum sapien. Phasellus pretium vestibulum est in porta. Mauris fringilla dapibus lectus vel venenatis. Nulla mauris nisl, iaculis non maximus eu, aliquam eget magna. Fusce magna massa, fringilla id posuere at, accumsan ut erat. Phasellus commodo molestie diam at laoreet. Maecenas lacinia justo in nulla dapibus, a luctus orci sagittis. Nulla ac semper urna.
Quisque pellentesque, eros non condimentum auctor, nibh arcu faucibus mi, eu lacinia erat ex nec dui. Suspendisse tincidunt lorem a turpis faucibus aliquet. Nunc eu ultrices mauris, in venenatis urna. Vivamus lobortis lorem ligula, sit amet faucibus magna venenatis a. Ut lobortis nunc urna, vel rhoncus nisl convallis eu. Vestibulum porta tellus justo, a elementum urna imperdiet at. Etiam et facilisis dui. Proin ut libero sodales, bibendum est in, elementum risus. Sed tincidunt, eros sed feugiat commodo, purus odio blandit neque, vitae maximus felis eros et erat. Sed gravida nunc a nulla iaculis iaculis. Pellentesque eget massa rhoncus ligula porta ullamcorper.
"
["post_title"]=>
string(39) "The most popular dish in our restaurant"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(4) "open"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(39) "the-most-popular-dish-in-our-restaurant"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2019-07-13 10:24:04"
["post_modified_gmt"]=>
string(19) "2019-07-13 10:24:04"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(28) "http://restaurant.loc/?p=139"
["menu_order"]=>
int(0)
["post_type"]=>
string(4) "post"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "2"
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Post)#1230 (24) {
["ID"]=>
int(137)
["post_author"]=>
string(1) "1"
["post_date"]=>
string(19) "2019-07-13 10:21:37"
["post_date_gmt"]=>
string(19) "2019-07-13 10:21:37"
["post_content"]=>
string(2316) "
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium, tortor vitae porttitor suscipit, sapien purus aliquet risus, eu finibus arcu ante nec risus
Загрузка останавливается или он висит на белом экране в ожидании ответа сервера?
<a href="<?php echo esc_url( get_category_link( $post->ID ) ); ?>"><?php echo esc_html( get_the_category()->cat_name ); ?></a>
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) {
return; // Exit if it is accessed directly
}
class ColorMag_Elementor_Widgets_Grid_2 extends Widget_Base {
/**
* Retrieve ColorMag_Elementor_Widgets_Grid_2 widget name.
*
* @access public
*
* @return string Widget name.
*/
public function get_name() {
return 'ColorMag-Posts-Grid-2';
}
/**
* Retrieve ColorMag_Elementor_Widgets_Grid_2 widget title.
*
* @access public
*
* @return string Widget title.
*/
public function get_title() {
return esc_html__( 'Grid Style 2', 'colormag' );
}
/**
* Retrieve ColorMag_Elementor_Widgets_Grid_2 widget icon.
*
* @access public
*
* @return string Widget icon.
*/
public function get_icon() {
return 'colormag-econs-grid-2';
}
/**
* Retrieve the list of categories the ColorMag_Elementor_Widgets_Grid_2 widget belongs to.
*
* Used to determine where to display the widget in the editor.
*
* @access public
*
* @return array Widget categories.
*/
public function get_categories() {
return array( 'colormag-widget-grid' );
}
/**
* Register ColorMag_Elementor_Widgets_Grid_2 widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @access protected
*/
protected function _register_controls() {
// Widget title section
$this->start_controls_section(
'section_colormag_featured_posts_grid_2_title_manage',
array(
'label' => esc_html__( 'Block Title', 'colormag' ),
)
);
$this->add_control(
'widget_title',
array(
'label' => esc_html__( 'Title:', 'colormag' ),
'type' => Controls_Manager::TEXT,
'placeholder' => esc_html__( 'Add your custom block title', 'colormag' ),
'label_block' => true,
)
);
$this->end_controls_section();
// Widget design section
$this->start_controls_section(
'section_colormag_featured_posts_grid_2_design_manage',
array(
'label' => esc_html__( 'Widget Title', 'colormag' ),
'tab' => Controls_Manager::TAB_STYLE,
)
);
$this->add_control(
'widget_title_color',
array(
'label' => esc_html__( 'Color:', 'colormag' ),
'type' => Controls_Manager::COLOR,
'default' => '#289dcc',
'scheme' => array(
'type' => Scheme_Color::get_type(),
'value' => Scheme_Color::COLOR_1,
),
'selectors' => array(
'{{WRAPPER}} .tg-module-wrapper .module-title span' => 'background-color: {{VALUE}}',
'{{WRAPPER}} .tg-module-wrapper .module-title' => 'border-bottom-color: {{VALUE}}',
),
)
);
$this->add_control(
'widget_title_text_color',
array(
'label' => esc_html__( 'Text Color:', 'colormag' ),
'type' => Controls_Manager::COLOR,
'default' => '#ffffff',
'scheme' => array(
'type' => Scheme_Color::get_type(),
'value' => Scheme_Color::COLOR_1,
),
'selectors' => array(
'{{WRAPPER}} .tg-module-wrapper .module-title span' => 'color: {{VALUE}}',
),
)
);
$this->end_controls_section();
// Widget posts section
$this->start_controls_section(
'section_colormag_featured_posts_grid_2_posts_manage',
array(
'label' => esc_html__( 'Posts', 'colormag' ),
)
);
$this->add_control(
'posts_number',
array(
'label' => esc_html__( 'Number of posts to display:', 'colormag' ),
'type' => Controls_Manager::TEXT,
'default' => 4,
)
);
$this->add_control(
'offset_posts_number',
array(
'label' => esc_html__( 'Offset Posts:', 'colormag' ),
'type' => Controls_Manager::TEXT,
)
);
$this->end_controls_section();
// Widget filter section
$this->start_controls_section(
'section_colormag_featured_posts_grid_2_filter_manage',
array(
'label' => esc_html__( 'Filter', 'colormag' ),
)
);
$this->add_control(
'display_type',
array(
'label' => esc_html__( 'Display the posts from:', 'colormag' ),
'type' => Controls_Manager::SELECT,
'default' => 'latest',
'options' => array(
'latest' => esc_html__( 'Latest Posts', 'colormag' ),
'categories' => esc_html__( 'Categories', 'colormag' ),
),
)
);
$this->add_control(
'categories_selected',
array(
'label' => esc_html__( 'Select categories:', 'colormag' ),
'type' => Controls_Manager::SELECT,
'options' => colormag_elementor_categories(),
'condition' => array(
'display_type' => 'categories',
),
)
);
$this->end_controls_section();
}
/**
* Render ColorMag_Elementor_Widgets_Grid_2 widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*
* @access protected
*/
protected function render() {
$posts_number = $this->get_settings( 'posts_number' );
$display_type = $this->get_settings( 'display_type' );
$offset_posts_number = $this->get_settings( 'offset_posts_number' );
$categories_selected = $this->get_settings( 'categories_selected' );
$args = array(
'posts_per_page' => $posts_number,
'post_type' => 'post',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
);
// Display from the category selected
if ( 'categories' == $display_type ) {
$args[ 'category__in' ] = $categories_selected;
}
// Offset the posts
if ( ! empty( $offset_posts_number ) ) {
$args[ 'offset' ] = $offset_posts_number;
}
// Start the WP_Query Object/Class
$get_featured_posts = new \WP_Query( $args );
?>
<div class="tg-module-grid tg-module-grid--style-2 tg-module-wrapper">
<?php
$widget_title = $this->get_settings( 'widget_title' );
if ( ! empty( $widget_title ) ) : ?>
<div class="tg-module-title-wrap">
<h4 class="module-title">
<span><?php echo $this->get_settings( 'widget_title' ); ?></span>
</h4>
</div>
<?php endif;
?>
<div class="tg-row thinner">
<?php
$count = 1;
while ( $get_featured_posts->have_posts() ) :
$get_featured_posts->the_post(); ?>
<?php
$thumbnail_image_size = 'colormag-highlighted-post';
$main_div_loop_wrapper_class = 'tg_module_grid tg_module_grid--small tg_module_grid--half tg-col-control';
if ( $count == 1 ) {
$thumbnail_image_size = 'colormag-elementor-grid-large-thumbnail';
$main_div_loop_wrapper_class = 'tg_module_grid tg_module_grid--full';
} else if ( $count == 2 ) {
$thumbnail_image_size = 'colormag-elementor-grid-medium-large-thumbnail';
$main_div_loop_wrapper_class = 'tg_module_grid tg_module_grid--small tg_module_grid--full tg-col-control';
}
if ( ( $count == 1 ) || ( $count == 2 ) ) :
echo '<div class="tg-col-control">';
endif;
if ( $count == 2 ) :
echo '<div class="tg-row thinner">';
endif;
?>
<div class="<?php echo esc_attr( $main_div_loop_wrapper_class ); ?>">
<?php
if ( has_post_thumbnail() ) : ?>
<figure class="tg-module-thumb">
<a href="<?php the_permalink(); ?>" class="tg-thumb-link">
<?php the_post_thumbnail( $thumbnail_image_size ); ?>
</a>
</figure>
<?php endif;
?>
<div class="tg-module-info">
<?php colormag_elementor_colored_category(); ?>
<h3 class="tg-module-title entry-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h3>
</div>
</div>
<?php
if ( $count == 1 ) :
echo '</div>';
endif;
$count ++;
endwhile;
if ( $count > 2 ) {
echo '</div>';
echo '</div>';
}
// Reset the postdata
wp_reset_postdata();
?>
</div>
</div>
<?php
}
}
Это не совсем то, что хотел, но так тоже можно логировать в файл не прописывая код в каждом файле.