Skip Navigation

[Résolu] If types field checked dont show post

This support ticket is created Il y a 7 années et 2 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Marqué : ,

This topic contains 12 réponses, has 3 voix.

Last updated by Beda Il y a 7 années et 2 mois.

Assisted by: Beda.

Auteur
Publications
#477268

I have a view and my customer has changed their mind on one point. Now the customer wants if a specific field is checked, the post must not be shown in the current view. Instead the post must be shown in another view.

Currently it works the following way:

[types field="solgt" option="1" state="checked"]Sold[/types][types field="solgt" option="1" state="unchecked"]kr. [types field='pris'],-[/types]

If the post has been checked as "solgt" (meaning sold), there is a text that says "Sold". If the post has not been checked then the price shows.

As saying the customer now wants all posts that has been sold to not display in the view. And posts that has been sold must be shown in another view.

How can this problem be solved?

Here is my Loop Output Editor:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          	<div class="col-md-3 col-sm-6 luft">
              	<div class="col-sm-12 maximg nopadding maximg">
              		[wpv-post-featured-image size="blogg_thumb"]
				</div>
              	<div class="clearfix"></div>                                    
              	<div class="padding lefttext color1 whitetext">
                  <h1 class="littluft twentyfive lefttext">[wpv-post-taxonomy type='kunstner' format='name']</h1>
                  <div class="col-sm-6 nopadding">
                    <a href="[wpv-post-url]" class="btn btn-small btn-small btn-outline-fill-color2 displayblock" role="button" title="[wpv-post-title]" onmouseover="this.title='';">[types field="solgt" option="1" state="checked"]Solgt[/types][types field="solgt" option="1" state="unchecked"]kr. [types field='pris'],-[/types]</a>
                  </div>
                  <div class="col-sm-6 nopadding">
                    <a href="[wpv-post-url]" class="btn btn-small btn-fill-color2 displayblock" role="button" title="[wpv-post-title]" onmouseover="this.title='';">Les mer</a> 
                  </div>
                  <div class="clearfix"></div>     
              	</div>
		</div>
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Looking forward to hear from you again,

#477344

Minesh
Supporter

Languages: Anglais (English )

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

Hello. Thank you for contacting the Toolset support.

What if you try to add query filter for your custom field and try to resolve your issue.

More info:
=> https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/

#479062

Thank you for getting back to me,

When I add a query filter with the following: Solgt is a string equal to 1 it shows posts that has been checked. I am however having troubles filtering out posts that has not been checked.

If I set it to Different from 1 it says "No items found". Same result if I set it to Not like 1.

Any ideas?

The results should show if the field has not been checked, since the problem with showing only checked has been solved.

#479068

Minesh
Supporter

Languages: Anglais (English )

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

What if you try to set the `filter as:

Different from (blank - do not enter any value and save the filter)
#479069

Thank you for trying to help me out,

I tried with Solgt is a string different from (no value), but it only shows posts that has been checked.

Also tried with Solgt is a string equal to (no value), but it does not shows any posts, just "No items found".

#479071

Minesh
Supporter

Languages: Anglais (English )

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

I think then the easiest way to go with is use Views filter hook: wpv_filter_query

Pleaes try to add following code to your current theme's functions.php file.

add_filter( 'wpv_filter_query', 'func_not_checked_posts', 10, 3 );
function func_not_checked_posts( $query_args, $view_settings, $view_id ) {
    if($view_id = 999999) {
        $query_args['meta_query'][] = array(
            'key'     => 'wpcf-solgt',
            'compare' => 'NOT EXISTS',
        );
    }
    return $query_args;
}

Where:
- Replace 999999 with your original view ID

More help:
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

#479074

Thank you for providing that,

Just a quick question. Is layout_id=22 the same as the View ID?

I see now that the page is a layout under Archive, and not listed under Views as I first thought. The page listed under Views turns out to be an old inactive view. I hope this not make any problems?

Looking forward to hear from you again,

#479079

Minesh
Supporter

Languages: Anglais (English )

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

No - when you navigate to: Toolset => Views

With this listing view's page you will see the column ID - so you need to use ID associated with your view name in same row. Please check following screenshot.
=> hidden link

#479081

Thank you for clearing that out,

I am sorry to inform you that I have misunderstood since this was a old page made 6 months ago, and I have forgotten which View and Layout that was active. Turns out the View is not active, and the current page was generated with an "Archive Layout" instead.

Should I close this case, and open a new case in Layouts instead of Views?

Looking forward to hear from you,

#479112

Minesh
Supporter

Languages: Anglais (English )

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

If your issue is different then you can. If you have still issue with displaying results with unchecked checkbox you can tell me here.

1)
Please share problem URL

2)
*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

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

#479295

Minesh
Supporter

Languages: Anglais (English )

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

I've added following code to your current theme's functions.php file:

Following code is responsible to filter the posts where checkbox is unchecked.

add_filter( 'pre_get_posts', 'func_not_checked_posts');
function func_not_checked_posts( $query) {	
    if(is_post_type_archive('kunst')) {
		$meta_query = array(
            'key'     => 'wpcf-solgt',
            'compare' => 'NOT EXISTS',
        );
		$query->set('meta_query', $meta_query);
    }
}

Could you please check and let me know you got desired results now.

#480160

Thank you,

Here is what I have now:

[wpv-control field="solgt" url_param="solgt" type="select" values=",1,0" display_values="Alle,Solgt,Null"]

Alle - Shows all posts, both sold and unsold.
Solgt- Shows sold posts.
Null does not show up.

So basically all I need now is something that shows only not sold posts.

Any ideas?

#480844

I am confused, as the ticket eveolved from "Show Posts with sold/not sold" values on separate Views, but then it seems you want now a Custom Search that actually let's the user display either Sold or not Sold Items in the same View?

Is that correct?

You can do that, but you'll need to remove Minesh's code, which should not be necessary anyway (I will need to know what you store for that field if it's not checked > 0 or nothing?)

But anyway, if you want a Custom Search for this field, you will initially set it up in the Filter editor and pass your Arguments with the GUI.

The view would always return ALL results at first (this is simply how Searches and queries work).
Then you could refine by "not sold" or "sold".

If this does not suite the needs, the only way to go is either a Query Filter, or a Custom HTML conditional as elaborated here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

Please let me know hwo the state of things is, so I can help you adequately.

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