Skip Navigation

[Resolved] Recent Toolset update broke output

This support ticket is created 6 years, 9 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.

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
- 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 17 replies, has 2 voices.

Last updated by rainman 6 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#546153
exposed-shortcode.png

I have a complex set of types and views which which setup by Toolset PAID support. Something seems to have changed with a recent Toolset update that broke some of the functionality. Looks like some of the code they used to build the loops must be deprecated or something.

Now I see shortcodes exposed on front end and repeating content. I have attached a screenshot from this page as an example: hidden link

The page is supposed to list the cases related to that lawyer broken down by their case status:
• Charges Dismissed After Warrant Issued
• Sexual Charges Dismissed After Indictment With Probation

As you scroll down the page, there should be a sub-heading with the related cases below it. Each of the "status" headings should only appear once on the page, with the relevant cases listed below it. As you can see, the headings are repeating many times along with the cases.

For the exposed shortcode shown in screenshot, this is the taxonomy loop code:

[wpv-layout-start]
 [wpv-items-found]
<!-- wpv-loop-start -->
   <wpv-loop>
     [if-check-taxonomy view_name="practice-areas-tax" taxonomy="[wpv-taxonomy-slug]"]
     	[wpv-view name="Cases status"]
     [/if-check-taxonomy]
   </wpv-loop> 
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-taxonomy-found][wpml-string context="wpv-views"]<strong>No taxonomy found</strong>[/wpml-string][/wpv-no-taxonomy-found]
[wpv-layout-end]

For the case listings by status, here is the loop code:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
   <wpv-loop>
     <div style="display:none;">
       [wpv-post-taxonomy-practice-area]; [wpv-post-slug]
       </div>
     [if-check-count view_name="cases-count-for-case-status" practicearea="[wpv-post-taxonomy-practice-area]" l="[wpv-post-slug]"]
     <div class="case-list" id="[wpv-taxonomy-slug]">
       <h2 class="taxonomy-title">[wpv-taxonomy-title]</h2>
       [wpv-view name="cases by status" practicearea="[wpv-post-taxonomy-practice-area]" l="[wpv-post-slug]"]
       <a class="back-to-top" href="#content">Back to top</a>
     </div>
     [/if-check-count]
   </wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found] 
[wpv-no-items-found][wpml-string context="wpv-views"]<strong>No taxonomy found</strong>[/wpml-string][/wpv-no-items-found]
[wpv-layout-end]

Can you help me fix this mess?

#546168

Shane
Supporter

Languages: English (English )

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

Hello,

Thank you for contacting our support forum.

Is this a custom shortcode ? [if-check-taxonomy ] if so could you let me know what does this shortcode do ?

Thanks,
Shane

#546169

Here is code that was added to my functions.php file by Toolset PAID support rep.

// get the post slug
add_shortcode('wpv-post-slug', 'wpv_post_slug_shortcode');
function wpv_post_slug_shortcode($atts) {
    extract( shortcode_atts( array(), $atts ) );
    $out = '';
	if (!empty($_GET['l']) && is_numeric($_GET['l'])) {
		$out = get_post_field('post_name', $_GET['l'], 'raw');
	}
    return $out;
}
//workaround for wpv-if statement when evaluating views results
add_shortcode( 'if-check-count', 'if_check_count_shortcode' );
function if_check_count_shortcode( $atts, $content = null ) {
	if ( ! empty ( $atts['view_name'] ) ) {
		$args = array(
			'name' => $atts['view_name']
		);
		if ( ! empty ( $atts['current_post'] ) ) {
			$current_post   = $atts['current_post'];
			$attorney_terms = get_the_terms( $atts['current_post'], 'attorney-tax' );
			if ( is_array( $attorney_terms ) ) {
				foreach ( $attorney_terms as $attorney ) {
					$args['attorneytax'] = $attorney->slug;
					break;
				}
			}
		} else {
			$current_post = '';
		}

		if ( ! empty ( $atts['practicearea'] ) ) {
			$args['practicearea'] = $atts['practicearea'];
		}

		if ( ! empty ( $atts['l'] ) ) {
			$args['l'] = $atts['l'];
		}

		add_filter( 'wpv_filter_' . str_replace( '-', '_', $view_name ), 'wpv_filter_' . str_replace( '-', '_', $view_name ) . '_func' );
		$string = str_replace( array( "\n", "\r", "\t" ), '', render_view( $args ) );
		remove_filter( 'wpv_filter_' . str_replace( '-', '_', $view_name ), 'wpv_filter_' . str_replace( '-', '_', $view_name ) . '_func' );
		$result = preg_match( '/<div\sid="wpv-view-.*>(.*?)<\/div>/', $string, $match );

		if ( $result && isset( $match[1] ) ) {
			sscanf( $match[1], '%d', $count );
			if ( is_numeric( $count ) && 0 == $count ) {
				$content = '';
			}
		}
	}

	return do_shortcode( $content );
}

function if_check_taxonomy_shortcode($atts, $content=null) {
    extract( shortcode_atts( array(
		'view_name' => '',
		'taxonomy' => '',
	), $atts ) );
	if ($view_name == 'practice-areas-tax') {
		$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
		if (isset($term->slug) && $term->slug == $taxonomy) {
		} else {
			$content = '';
		}
	}
	return do_shortcode($content);
}
add_shortcode('wpv-post-taxonomy-practice-area', 'wpv_post_taxonomy_practice_area_shortcode');
function wpv_post_taxonomy_practice_area_shortcode($atts) {
	$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
	return $term->slug;
}
//filter hook to allow execution of view filter code 
function wpv_filter_cases_count_for_case_status_func($filter) {
	return true;
}
// filter properly the 'cases-count-for-case-status' view
add_action('pre_get_posts', 'filter_cases_count_for_case_status');
function filter_cases_count_for_case_status($query) {
	if (!isset($query -> query_vars['post_type']))
			$query -> query_vars['post_type'] = false;
	if (!is_admin() && is_array($query->query_vars['post_type']) && in_array('cases', $query->query_vars['post_type'])) {
			$taxonomies = array(
			'attorney-tax'=>array('url_param'=>'l', 'type'=>'post_id'),
			'practice-area'=>array('url_param'=>'practice-area', 'type'=>'slug')
		);
		$enter_filter = apply_filters('wpv_filter_cases_count_for_case_status', false);
		if ($enter_filter) {
			$tax_query = $query->query_vars['tax_query'];
			$tax_query_values = array_key_values('taxonomy', $tax_query);
			foreach ($taxonomies as $taxonomy=>$settings) {
				if (!in_array($taxonomy, $tax_query_values)) {
					$terms = array();
					switch ($settings['type']) {
						case 'post_id':
  							if (isset($_GET[$settings['url_param']]) && is_numeric($_GET[$settings['url_param']])) {
								$post_name = get_post_field('post_name', $_GET[$settings['url_param']], 'raw');
								if (!empty($post_name)) {
									$terms = get_term_by('slug', $post_name, $taxonomy);
									if ($terms) {
										$terms = array($terms->term_id);
									}
								}
							}
							break;
						case 'slug':
							$slug = '';
							$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
							if ($term->taxonomy == $taxonomy) {
								$slug = $term->slug;
							}
							if (!empty($slug)) {
								$terms = get_term_by('slug', $slug, $taxonomy);
								if ($terms) {
									$terms = array($terms->term_id);
								}
							}
							break;
					}
					if (!is_array($terms)) {
						$terms = array();
					}
					$tax_query[] = array(
						'taxonomy' => $taxonomy,
						'field' => 'id',
						'terms' => $terms,
						'operator'=> 'IN'
					);
				}
			}
			$query->set('tax_query', $tax_query);		
		}
	}
}

// recursive get array values by key
function array_key_values($needle, $haystack) {
	$output = array();
	foreach($haystack as $key => $value){
		if($key === $needle && !is_array($value)){
			$output[] = $value;
		} else if (is_array($value)) {
			$output = array_merge($output, array_key_values($needle, $value));
		}
	}
	return $output;
}

// dequeue wp-types front-end scripts and stylesheets
add_action( 'wp_enqueue_scripts', 'prefix_remove_views_assets', 20 );
 
function prefix_remove_views_assets() {
 
	// Scripts
	 
	// views_front_end_utils.js - used in Views parametric searches
	wp_deregister_script( 'wpv-front-end-utils' );
	 
	// wpv-pagination-embedded.js - used in Views pagination and table sorting
	wp_deregister_script( 'views-pagination-script' );
	 
	// jquery.ui.datepicker.min.js and wpv-date-front-end-control.js - used in Views parametric searches by a date field
	wp_deregister_script( 'jquery-ui-datepicker' );
	wp_deregister_script( 'wpv-date-front-end-script' );
	 
	// Styles
	 
	// wpv-views-sorting.css - used in Views table sorting
	wp_deregister_style( 'views-table-sorting-style' );
	 
	// wpv-pagination.css -used in Views pagination
	wp_deregister_style( 'views-pagination-style' );
 
}
#546217

Shane
Supporter

Languages: English (English )

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

Hello,

Thanks for the information.

From what I see this code should still function normally, however there is a missing function to register your shortcode.

Add the following to your functions.php file and let me know if it helps.

add_shortcode('if_check_taxonomy','if_check_taxonomy_shortcode');

Thanks,
Shane

#546228

That didn't do anything at all.

#546235

Shane
Supporter

Languages: English (English )

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

Hello,

Could you provide me with admin access to the website so I can have a look .

Also could you let me know the forum post that you got the assistance with this code for?

Thanks,
Shane

#546267

Shane
Supporter

Languages: English (English )

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

Hello,

Thank you for the credentials but could you let me know which view I should be looking at also please let me know the original thread that you got this code from.

Thanks,
Shane

#546273

I don't know the original thread for sure because there have been several. Maybe #327394 or #112123. But I paid for custom work which was done by Ana Couto originally and then there were some Toolset changes and the original stuff had to be modified to work. And now this.

I believe there are two Views involved:
• Cases status
• cases by status

#546928

Shane
Supporter

Languages: English (English )

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

Hello,

What I can do is to check with Ana for you on this. Also I'm having issue with finding the view that has this shortcode if-check-taxonomy

Could you let me know which view that shortcode is on.

Thanks,
Shane

#546937

It is view ID 103 - Practice Areas - tax

#547488

Shane
Supporter

Languages: English (English )

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

Hello,

I've contacted Ana for some assistance on this one.

Thanks,
Shane

#547633

This is a live site so it is an URGENT issue.

I'm very concerned about continuing to use Toolset in the future because this is the 3rd time the website has broken due to changes to the Toolset plugin.

Please give an ETA

#547939

Shane
Supporter

Languages: English (English )

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

Hello,

Ana is currently taking a look at the site so once I get any information from her I will let you know.

Thanks,
Shane

#548381

Shane
Supporter

Languages: English (English )

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

Hello,

The issue should now be resolved.

Thanks,
Shane

#548392
issue.png

Thanks! What did you do? I need some documentation on the changes.

Also, I still see ONE MORE PROBLEM. What is the "Property Areas" shown in attached screenshot? I don't think that is supposed to be there.

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