I’m trying to use a custom query in my elementor project in combination with a post widget. Since I need to create a custom layout, my idea is to get custom post type using the custom query way of elementor development documentation.
I’ve added a single post widget in each column of my container, and I’ve assigned a specific query ID. In my php code I now have added this code to dump the query and see if all is working fine, and I’m able to do a var_dump
on the query but I’m unable to understad if the posts are correctly extracted.
this is the var_dump result on the $query
variable
object(WP_Query)#3418 (50) { ["query"]=> array(10) { ["posts_per_page"]=> int(1) ["paged"]=> int(1) ["has_custom_pagination"]=> bool(false) ["post_status"]=> string(7) "publish" ["post_type"]=> string(9) "portfolio" ["orderby"]=> string(9) "post_date" ["order"]=> string(4) "desc" ["ignore_sticky_posts"]=> bool(false) ["post__not_in"]=> array(1) { [0]=> int(1109) } ["date_query"]=> array(0) { } } ["query_vars"]=> array(61) { ["posts_per_page"]=> int(1) ["paged"]=> int(1) ["has_custom_pagination"]=> bool(false) ["post_status"]=> string(7) "publish" ["post_type"]=> string(9) "portfolio" ["orderby"]=> string(9) "post_date" ["order"]=> string(4) "desc" ["ignore_sticky_posts"]=> bool(false) ["post__not_in"]=> array(1) { [0]=> int(1109) } ["date_query"]=> array(0) { } ["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) "" ["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) "" ["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_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) { } ["search_columns"]=> array(0) { } ["post_title"]=> string(6) "test 6" } ["tax_query"]=> object(WP_Tax_Query)#3417 (6) { ["queries"]=> array(0) { } ["relation"]=> string(3) "AND" ["table_aliases":protected]=> array(0) { } ["queried_terms"]=> array(0) { } ["primary_table"]=> NULL ["primary_id_column"]=> NULL } ["meta_query"]=> bool(false) ["date_query"]=> bool(false) ["post_count"]=> int(0) ["current_post"]=> int(-1) ["before_loop"]=> bool(true) ["in_the_loop"]=> bool(false) ["comment_count"]=> int(0) ["current_comment"]=> int(-1) ["found_posts"]=> int(0) ["max_num_pages"]=> int(0) ["max_num_comment_pages"]=> int(0) ["is_single"]=> bool(false) ["is_preview"]=> bool(false) ["is_page"]=> bool(false) ["is_archive"]=> bool(true) ["is_date"]=> bool(false) ["is_year"]=> bool(false) ["is_month"]=> bool(false) ["is_day"]=> bool(false) ["is_time"]=> bool(false) ["is_author"]=> bool(false) ["is_category"]=> bool(false) ["is_tag"]=> bool(false) ["is_tax"]=> bool(false) ["is_search"]=> bool(false) ["is_feed"]=> bool(false) ["is_comment_feed"]=> bool(false) ["is_trackback"]=> bool(false) ["is_home"]=> bool(false) ["is_privacy_policy"]=> bool(false) ["is_404"]=> bool(false) ["is_embed"]=> bool(false) ["is_paged"]=> bool(false) ["is_admin"]=> bool(false) ["is_attachment"]=> bool(false) ["is_singular"]=> bool(false) ["is_robots"]=> bool(false) ["is_favicon"]=> bool(false) ["is_posts_page"]=> bool(false) ["is_post_type_archive"]=> bool(true) ["query_vars_hash":"WP_Query":private]=> string(32) "dde53a81e3d1ee97516abbcf05188915" ["query_vars_changed":"WP_Query":private]=> bool(false) ["thumbnails_cached"]=> bool(false) ["allow_query_attachment_by_filename":protected]=> bool(false) ["stopwords":"WP_Query":private]=> NULL ["compat_fields":"WP_Query":private]=> array(2) { [0]=> string(15) "query_vars_hash" [1]=> string(18) "query_vars_changed" } ["compat_methods":"WP_Query":private]=> array(2) { [0]=> string(16) "init_query_flags" [1]=> string(15) "parse_tax_query" } }
This is the PHP code
add_action('elementor/query/top_left_portfolio_column', function( $query ){
$query->set('post_type', 'portfolio');
//$query->set('posts_per_page', 3);
var_dump( $query );
});
From the dump I can see that the custom query is executed, but I’m not able to get posts details.
How I will get only the post links, titles and featured images of my custom post type with the query? I can also have a custom pagination that will update the displayed posts when a button is clicked (also button can be used to do custom actions in elementor)?