Skip Navigation

[Resolved] types_get_field adds extra character for default option

This support ticket is created 6 years, 3 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by davidS-53 6 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1105380
Screenshot 1.png
Screenshot 2.png

I have a select field (see screenshot 1) with a range of values set.

I also have the following function to create a set of filters of the values from that field for the purposes of filtering posts in a view based on the value of the interval field:

        // Interval Filters - Need to fix
	// =============================================================================
	function interval_shortcode() {
		$current_url = $_SERVER['REQUEST_URI'];
		$noInterval = explode("&", $current_url)[0];
		$interval_dropdown = "<a class='x-btn x-btn-mini' href='{$noInterval}'>SHOW ALL</a> ";
		$field = types_get_field( 'interval');
		foreach ( $field['data']['options'] as $option ) {
		    $title = $option['title'];
		    $value = $option['value'];
		    $interval_dropdown .= "<a class='x-btn x-btn-mini' href='{$current_url}&interval={$value}'>{$title}</a> ";
		}
		return "<span class='interval-dropdown'>" . $interval_dropdown . "</span>";
	}
	add_shortcode('wpv-interval-filter', 'interval_shortcode');

Now take a look at screenshot 2. There's a random W in there. I've managed to work out that it's something to do with the default field. I can change the default value, and the W moves. Question is, how can I stop it showing up??

I also tried changing to the no default option, but then I get an N at the end instead...

Cheers!

#1105389

There is also an htaccess password on the site. If you go to https://toolset.com/forums/topic/post-relationship-doesnt-save/ you'll find the user/pass to get around that in the secure note for that.

#1105551

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for contacting our support forum.

What you can do is to add an if statement to your code to filter out this default option.


 foreach ( $field['data']['options'] as $option ) {
        $title = $option['title'];
        $value = $option['value'];
        if($title != "W"){
              $interval_dropdown .= "<a class='x-btn x-btn-mini' href='{$current_url}&interval={$value}'>{$title}</a> ";
         }
    }

Try this and let me know if it helps.

Thanks,
Shane

#1106422

Looked good to me, but doesn't work sorry. To try debug it a little I did the following:

This hides the Weekly label:

 if($title != "Weekly"){

This does nothing:

 if($value!= "W"){
#1106850

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

I was under the impression that the title would've been W.

So as you says weekly works fine right ?

Thanks,
Shane

#1111328

Yeah. As I said, it's something to do with how the default option is stored.

Changing the default option changes the position of the W to after whatever the default option is.

Setting no default puts a N at the start.

#1112410

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

For now this workaround will have to work.

However can you confirm that the issue still remains in our latest version ?

Thanks,
Shane

#1112425

Ahh- I was about to comment and say that your solution didn't work- but noted that the interval is stored lowercase, and your solution has it uppercase. Changing it to

if($value != "w"){

works. Bit of a strange workaround but nothing new.

#1112679

My issue is resolved now. Thank you!