Skip Navigation

[Resolved] Passing Post Ids into get_view_query_results as $args

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by Minesh 1 year, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2615101

Tell us what you are trying to do?
I want to use php to get data from a view - and pass through post IDs to select specific posts to display.

I've do this in shortcode: [wpv-view name="Filter by post id" ids="302,12,309"]
As it says here: https://toolset.com/documentation/legacy-features/views-plugin/filtering-views-query-by-post-id/

I'm doing this:
$args = array('ids' => '39090,38975', 'order' => 'asc');
$posts = get_view_query_results(38943,null,null,$args);
print_r($posts);

The 'order' bit is working - I can change the order by switching asc or desc.

The 'ids' bit is not. It makes no difference what I put in this area.

Is there some other documentation I need to follow to make this work?

#2615225

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to review your view settings first. Can you please send me edit screenshot of your view page.

#2615283
Screenshot 2023-06-13 at 09.37.24.png
Screenshot 2023-06-13 at 09.36.58.png
Screenshot 2023-06-13 at 09.35.58.png

Hi Minesh - lots of screenshots attached.
I have tried different settings and different IDs - making sure the IDs I am calling are included in the default list from the view.

The view is limited to 5 results - but the IDs are included in those 5 results anyway.

#2615311

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share admin access details and problem URL where you are trying to display the result and also tell me where you added the code you shared with what PHP template.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2615321

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I'm not sure what should have happen but when I visit the page where you added your view:
=> hidden link

I found that with the view there was no query filter added for the post ID. So I've added the post ID filter and saved the page and I can see it does return the two results.
=> hidden link

#2615323
Screenshot 2023-06-13 at 10.48.19.png

Hi Minesh,
The filter was in place when I took the screenshot I sent. (and it was not working)
I then removed it to see if that made a difference (and it did not.) - which was why it was not set when you looked at it.

I have all sorts of problems with the filters Minesh. They disappear after set - I have to add a new filter (of any sort) just to be able to see the filters I already have set. And then I need to delete that filter before publishing changes.

I really wish the filters I have set would just be there when I load the page!

WHen I load that view page - I see the attached. It looks like there are no filters set at all. But we both know there are some.
The only way I can see them is by adding a NEW filter (which I then have to delete later).

Having said all that - it does seem to be working as expected now.

#2615335

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that solution I shared help you to resolve your issue. You are welcome to mark resolve this ticket.

#2615411

Thanks Minesh.
Just beore you go:

Is there a way to pass post IDs in to: render_view
https://toolset.com/documentation/programmer-reference/views-api/#render_view

It doesn't look like it but I just want to be sure I'm not missing something there.

Thanks

#2615431

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - you cam use the render_view() function as well and pass the ids argument to it.

For example:

$args = array('ids' => '39090,38975', 'order' => 'asc');
echo render_view( $args );