Skip Navigation

[Resolved] Unable to query Toolset custom post in elementor custom query

This support ticket is created 2 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 3 voices.

Last updated by himanshuS 2 years ago.

Assisted by: Luo Yang.

Author
Posts
#2323487

Hey there,
I can't make elementor custom query to work for post__in attribute with Toolset for a CPT called company. I am passing the post ids as an array but the query just does not run. All of my other queries work except the ones with post__in. So it seems like elementor custom query is working fine. I wanted to check with you if you have seen a similar issue from other users and is this related to compatibility between Toolset and elementor.

Here is the array data - hidden link

code -

add_action( 'elementor/query/filter-company-level-recommendations-v2', function( $query ) {
$current_user_id = get_current_user_id();
$args = array (
'author' => $current_user_id,
'post_type' => 'company',
'post_status' => 'publish'
);

$company_posts = get_posts($args);
$company_id = $company_posts[0]->ID;
$matched_candidates_meta = get_post_meta($company_id, 'wpcf-matched-candidates-meta', false);
$custom_match_data_json = $matched_candidates_meta[0];
$matched_candidate_array = json_decode($custom_match_data_json, true);

foreach($matched_candidate_array as $entry) {
$portfolio_ids_array[] = $entry['portfolio-id'];
}
$query->set( 'post__in', $portfolio_ids_array);
} );
#2323745

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

I'm not familiar with Elementor's query API, but the code you shared looks reasonable.

The first thing I would do is check whether it can work, i.e. instead of the above logic simply pass a hard-coded list of post IDs (sensible ones that you know should give the expected results), e.g.

add_action('elementor/query/filter-company-level-recommendations-v2', function ($query) {

    $portfolio_ids_array = array( 123, 234, 345 );
    $query->set('post__in', $portfolio_ids_array);
});

Does that work? If not then what you are aiming to do doesn't seem possible. Elementor should have more information.

If it does then it would seem that there is a flaw in your code logic that will require some debugging.

For each variable you create, try dumping it to the debug.log to see if it gives the expected results, and in particular make sure that $portfolio_ids_array actually contains the expected array of IDs, e.g.

    foreach ($matched_candidate_array as $entry) {
        $portfolio_ids_array[] = $entry['portfolio-id'];
    }
    error_log( print_r($portfolio_ids_array, true) );
    $query->set('post__in', $portfolio_ids_array);
#2327081

Thanks, Nigel. This makes sense. I am working on it and will get back to you soon.

#2328487

Hello,

Please update here if you still need assistance for it.

#2328831

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.