Skip Navigation

[Resolved] conditional display with custom field

This support ticket is created 4 years, 11 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)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Shane 4 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#1768323

I've tried this code below to conditionally display related expertises for one professional;

/// Array contain string shortcode
add_shortcode( 'wpv-array-contain-string', 'array_contain_string');
function array_contain_string($atts) {
    global $wp_query;
    global $post;
  extract( shortcode_atts( array(
    'string' => '',
    'array' => ''
  ), $atts) );
  $result = "false";
    $list = get_post_meta($wp_query->post->ID,'wpcf-prof-exp-order');
    $exp_id = get_post_meta($post->ID, 'wpcf-exp-id');
 $array = explode( ',' , $list[0] );  
 if (in_array($exp_id[0], $array)){
     $result = "true";
    }
  return $result;
}
//END Array contain string shortcode

From this view currently, I could get the expertise ordered by custom field "exp-id", which could be set on the view setting page.

What I want to do here is to set the order by 'wpcf-prof-exp-order' string value.

For example, if 'wpcf-prof-exp-order' has the string value of "304,502,103,104",
the current view shows 'exp-id'=103, 'exp-id'=104, 'exp-id'=305,'exp-id'=502.
What i want to show => 'exp-id'=304, 'exp-id'=502, 'exp-id'=103, 'exp-id'=104

Is it possible by adding custom function and if so, could you help me doing this?

#1768411

Shane
Supporter

Languages: English (English )

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

Hi Geunhee,

Thank you for getting in touch.

Unfortunately you wouldn't be able to sort this view by the "wpcf-prof-exp-order" field given that the post type that this view displays doesn't have the wpcf-prof-exp-order sort order field if I remember correctly.

Also even if you were able to sort the view by this field, you won't be able to get it to sort like this " 'exp-id'=304, 'exp-id'=502, 'exp-id'=103, 'exp-id'=104".

As you can see this sort order is neither Ascending or Descending. It is essentially a random order.

Thanks,
Shane