Skip Navigation

[Resolved] Unable to use Block Editor for Views

This support ticket is created 4 years, 8 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 39 replies, has 2 voices.

Last updated by GinaM9227 4 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1592761
query_filter3.jpg

> I already shared a test page that holds the Block view which is created by following the steps I already mentioned.

Yes and I used your test page and created a View for Products - See here: hidden link

Next, I want to be able to use Query Filter to especify which products I want to show. I need to exclude some products from the list.

- How do I use Query Filter together with the Blocks page you created? I have the Query settings that I need but it's on the old Classic Editor.

#1593739

Minesh
Supporter

Languages: English (English )

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

Once you click on your block view on the test page:
=> hidden link

On the right sidebar, you will see the option Search to activate the search on your view, which you need to activate and once you activate it, it will add search section on your block view and using the button "Add Search field" you can add as many frontend filters as you want. Please check the following screenshot:
=> hidden link

Please check the following video that shows how you can add the search filters:
=> hidden link

#1597023

Thank you. I looked at the video and it's not quiet what I'm looking to do. I need to create a view that excludes certain items but I do not want users to be able to search.

For example: In the view that I want to create, I would exclude all Products older than a certain date and exclude all Products that are not of the Ticket Taxonomy.

What I don't want is for Users to be able to search..the View should just be presented.

#1598763

Minesh
Supporter

Languages: English (English )

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

That means you just need to add Query filters to your view and you do not want to present the forntend filters.

You can simply add your query filters from the Query filter section. Once you select your view block on the right side you will see the Query Filter tab from where you can add your query filters to filter your view. Please check the following screenshot:
=> hidden link

You can add whatever query filters as per your requirement.

#1598807
query_filter.jpg
query_filter2.jpg

I added the Query Filters but cannot get it to work.

1) Show product-type = ticket-event
2) Show Dates equal to or Later than Today

See attached

#1598827

Minesh
Supporter

Languages: English (English )

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

"product_type" is the hidden taxonomy used by WooCommerce to store the product type. You need to use view's hook wpv_filter_query in order to query the simple products.

For example - please add following code to your current theme's functions.php file or "Custom Code" section offered by Toolset.
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_filter( 'wpv_filter_query', 'func_filter_ticket_products', 101, 3 );
function func_filter_ticket_products( $query_args, $view_settings, $view_id ) {
      
    if ( $view_id == 3313) { 
  
        $query_args['tax_query'] = array(
          array(
            'taxonomy' => 'product_type',
            'field' => 'slug',
            'terms' => array('ticket-event'),
            'operator' => 'IN'
          )
    }
  
    return $query_args;
}
#1598839
query_filter3.jpg

I found this documentation which advises to use the Date filter as a Number - I did that and now the Views is not showing any products..

https://toolset.com/documentation/user-guides/views/date-filters/

#1598849

Minesh
Supporter

Languages: English (English )

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

The _start_date_picker is not a Types field so you should keep using Date. I've already adjusted the field.

And you can apply the code I shared to filter with your product_type. I hope that is enough now.

#1598855
query_filter4.jpg

I fixed the Functions.php using your code and was going to edit the Query Filter in the Views but something happened and I cannot log to Admin..see attached

maybe it's the code?

#1598873

Here is the error message:

An error of type E_PARSE was caused in line 335 of the file /home/congenia/public_html/wp-content/themes/oceang/functions.php. Error message: syntax error, unexpected '}', expecting ')'

There must be an error in the code

#1598877

Minesh
Supporter

Languages: English (English )

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

ahh, silly error. semicolor was missing.

Please try to use the following code:


add_filter( 'wpv_filter_query', 'func_filter_ticket_products', 101, 3 );
function func_filter_ticket_products( $query_args, $view_settings, $view_id ) {
       
    if ( $view_id == 3313) { 
   
        $query_args['tax_query'] = array(
          array(
            'taxonomy' => 'product_type',
            'field' => 'slug',
            'terms' => array('ticket-event'),
            'operator' => 'IN'
          ));
    }
   
    return $query_args;
}

#1598927
query_filter6.jpg
query_filter5.jpg

Attached is the new Query Filter -

However, No products are showing on the Preview..

#1598975

Minesh
Supporter

Languages: English (English )

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

Ok I see the code I shared applied successfully.

Now, I see two event start dates. Which event start date you are referring to? the Start date available with woocommerce General settings or the custom field you created?

#1599161
queryfilter2.jpg
queryfilter1.jpg

The Query Filter for product type does not seem to work since it is still returning non Ticket items - see attached.

#1599183

Minesh
Supporter

Languages: English (English )

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

To apply the product type filter you do not need to add the query filter (so I removed it). The code I shared is enough to apply the the product_type filter.

Now, if you check the membership post: hidden link
- The post is set to Event Ticket that is why its displaying.