Skip Navigation

[Resolved] view inside a parameter of another view

This support ticket is created 2 years, 6 months 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
- 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 5 replies, has 2 voices.

Last updated by henriqueD 2 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#2402453

Hello how are you? I need help...

In my project, I have two views:

1st View:
[wpv-view name='get-countries-ids']
which returns a result like this: "id, id, id, id" (there can be any number of ids). ex: "9, 8, 7, 6"

2nd View:
[wpv-view name='get-city-names' countriesids="9, 8, 7, 6"]
returns the list with the name of the cities that have the field "country_id" with one of the values of the parameter "countriesids" passed in the shortcode

Both views work perfectly.

But when I put it like this, it doesn't work:
[wpv-view name='get-city-names' countriesids="[wpv-view name='get-countries-ids']"]

What happens? can't I use a shortcode inside another?

Details:
- the result of the 1st view is correct, always ids followed by a comma;
- I need it to be passed as a shortcode parameter only;
- I'm using the views plugin 3.6.3 with pure code;

I'm waiting.

Thanks

#2402517

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Have you check-mark the checkbox "Disable the wrapping DIV around the View" for the view "get-countries-ids".

You can find this "Disable the wrapping DIV around the View" just above "Output Editor" section. Does that helps?

if you still have issue, please share problem URL and admin access details and I'm happy to look at whats is the issue.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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.

#2403471

Minesh
Supporter

Languages: English (English )

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

Normally, the nested shortcodes should work but your case is bit complicated where you have nested shortcodes and view shorcodes has another nested shortcodes as view argument that fails to render correctly.

Fortunately, I've workaround to offer you.

Can you please check now: hidden link

This is how I've added the view now to your content template:
=> hidden link

[wpv-view name='pesquisa-produtos' idspost='[wpv-view name="campos-colecoes-por-produto" field="colecao-produtos"]']

Where I've removed the argument idspost='[wpv-post-id]'

I've added the following view filter to filter the "campos-colecoes-por-produto" view and added the filter at "Custom Code" section offered by Toolset:
=> hidden link

add_filter( 'wpv_filter_query', 'func_adjust_view_args', 10, 3 );
function func_adjust_view_args($query, $setting, $views_ID){
  
    if($views_ID == 1317) {
     
      $query['meta_query'] = array(
        		'relation' => 'AND',
          		array(
                    'key' => 'cc-produtos',
                    'value' => $post->ID,
                    'type' => 'CHAR',
                    'compare' => 'LIKE'
                )
      		);                   
    }
    return $query;
}

What we have done is removed the query filter for custom field 'cc-produtos' that is set to filter by shortcode attribute t idspost='[wpv-post-id]' and now we added that filter using wpv_filter_query hook.

#2403667

Hello,

I could understand the logic that you implemented, but it seems that it is not working.

from what I saw here, the variable "$post->ID" is not bringing anything. as it is empty, the query returns all posts.

but this test page (id: 575) is linked to only 3 "collections".

in the code passed when changing the variable "$post->ID" for "575" the view brings the correct content.

I tried to look for everything when it's the way, but I didn't find a variable with the correct id of the current post.

can you check it please?

That's all it takes to finish the system.

I'll be waiting and thank you

#2403671

Minesh
Supporter

Languages: English (English )

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

Could you please try to use the following code:
- I missed to define the global $post;

add_filter( 'wpv_filter_query', 'func_adjust_view_args', 10, 3 );
function func_adjust_view_args($query, $setting, $views_ID){
   global $post;
    if($views_ID == 1317) {
      
      $query['meta_query'] = array(
                'relation' => 'AND',
                array(
                    'key' => 'cc-produtos',
                    'value' => $post->ID,
                    'type' => 'CHAR',
                    'compare' => 'LIKE'
                )
            );                   
    }
    return $query;
}

It should work OK now.

#2403685

My issue is resolved now. Thank you!