Whats best practice for passing parameters into a view via php

By: Naomi Spirit | Asked: 12/01/2023
ForumsCategory: General questionsWhats best practice for passing parameters into a view via php
Naomi SpiritNaomi Spirit asked 8 months ago

I have a view set up with various parameters to filter it. When I "view" the view from the link in the plugin dashboard and add the parameters as query vars it's working as expected.  URL like so ***/frm_display/tw-submissions-2/?artist_user_id=6923&show_private=No

However, viewing the form using query vars isn't ideal for how I want it in my site. When I try and put the same view on a page and pass the parameters in as code it's not working. Here is what I've tried so far.

echo FrmViewsDisplaysController::get_shortcode( array( 'id' => '52610', 'artist_user_id' => '6923', 'show_private' => 'No') );

//doesn't work  

echo do_shortcode('[frm-set-get artist_user_id=7312 show_private="No"]');
echo do_shortcode('[display-frm-data id='52610' ]'); //doesn't work  

//doesn't work  

echo do_shortcode('[frm-set-get artist_user_id=7312 show_private="No"]');
FrmViewsDisplaysController::get_shortcode( array( 'id' => '52610') );

// doesn't work

Can anyone help?  Or point me in the direction of a working example?

1 Answers
Victor Font answered 8 months ago
Your first example should be close to working. You left off the filter parameter, but I'm not sure that matters. When displaying a view with the PHP alternative, all optional parameters that can be used with the [display-frm-data] shortcode may be used in the PHP call as well. Because you're not receiving a result, did you configure the view filter correctly with the [get param] shortcode. Does your view's filter have [get param="artist_user_id"] and [get_param="show_private"] applied to the correct fields in the form?
Victor Font replied 8 months ago

BTW, why are you using the PHP alternative? I'm curious.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right