Skip Navigation

[Resolved] Using shortcode inside view loop with custom field as attribute

This support ticket is created 2 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 6 replies, has 2 voices.

Last updated by Sotiris Krontiris 2 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2114703

I am trying to call a custom shortcode that I have created that takes one argument [wpv-post-id].
So the syntax is like this inside the loop editor:

    [wpv-post-id output='raw']
    [get_image custom_post_id='[wpv-post-id output="raw"]']
    [get_image custom_post_id='777777']

I expected to see the image html tag formatted but all I get is the below
777777
[get_image custom_post_id='777777']
[get_image custom_post_id='777777']

I have registered the shortcode in the Toolset->Settings->Front-end Content->Third-party shortcode arguments.
But the shortcode seems not to be evaluated at all.
I have another custom shortcode that it does get evaluated.
Is there a limitation on the number of the custom shortcode I can register.
I have 44 shortcodes listed in the Third-party shortcode arguments.

#2115051

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

There is no really limitation about how many shortcodes you register.

I need to check why the shortcode does not get evaluated. Where you added the shortcode and on what view?

*** 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 have set the next reply to private which means only you and I have access to it.

#2115095

Minesh
Supporter

Languages: English (English )

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

I can see with the staging site you shared you are using outdated Toolset plugins. We always recommend running your site with the latest stable release plugin version.

*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest officially released version. You can download the latest plugin release from your accounts page:
=> https://toolset.com/account/downloads/

Please let me know once you update ALL Toolset plugins - does it works with latest Toolset plugins?

#2115191

I have just update ALL toolset plugin and the issue still remains.

#2115295

The other similar code that does get evaluated in on another view with id "132537" and the shortcode is

[bb-profile-image memberid='[wpv-post-author format="meta" meta="ID"]']
#2116731

Minesh
Supporter

Languages: English (English )

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

I've changed the shortcode names to: [get_vessel_image1 vessel_id='[wpv-post-id output="raw"]']

And moved the following code to the functions.php file:

function vsl_vesselImage1($imo, $mmsi = '', $width = 746, $height = 560, $output_format = 'img_tag', $limit = '')
{
  global $wpdb;
  $return = "";
  $image_array = [];
  $sql = "select Image from wp_ship_img_names where " . (!empty($imo) ? " IMO='{$imo}'" : " MMSI='{$mmsi}'") . " order by Image";
  vsl_debug_log("[ Vessel Photos info ]===============================================");
  vsl_debug_log("Foto SQL:{$sql}");
  vsl_debug_log("Limit: {$limit}");

  $imgset = $wpdb->get_results($sql);
  vsl_debug_log("Imageset : {$imgset}");
  if (!empty($imgset)) {
    $srvpath = "<em><u>hidden link</u></em>";
    if ($limit == "1") {
      $foto = $imgset[0]->Image;
      //remove 1st catalog
      $path = explode('/', $foto);
      $foto = (count($path) > 0 ? $srvpath . $path[1] : '');
      switch ($output_format) {
        case 'img_tag':
          $return = "<img src='{$foto}' width='{$width}' height='{$height}'></img>";
          break;
        case 'img_uri':
          $return = $foto;
          break;
      }
      return $return;
    } else {
      foreach ($imgset as $image) {
        //remove 1st catalog
        $path = explode('/', $image);
        $image = (count($path) > 0 ? $srvpath . $path[1] : '');
        switch ($output_format) {
          case 'img_tag':
            $this_image = "<img src='{$image}' width='{$width}' height='{$height}'></img>";
            break;
          case 'img_uri':
            $this_image = $image;
            break;
        }
        array_push($image_array, '"' . $this_image . '"');
        vsl_debug_log("Image array");
        vsl_debug_log($image_array);
      }
      vsl_debug_log("final array: {$image_array}");
      return $image_array;
    }
  }
  return null;
}

/**
 * Return the vessel image when given the vessel ID
 * 
 */
add_shortcode('get_vessel_image1', 'vessel_image_shortcode1');
function vessel_image_shortcode1($atts) {
  
  
  
  $a = shortcode_atts(
    array(
      'vessel_id' => 0,
      'width' => 746,
      'height' => 560
    ),
    $atts
  );
  global $wpdb;
  $image_width = $a['width'];
  $image_height = $a['height'];
  $vessel_id = esc_attr($a['vessel_id']);
 vsl_debug_log("Vessel ID: " . $vessel_id);
   $vessel_post = get_post($vessel_id);
  $vessel_meta = get_post_meta($vessel_id);
  $vessel_name = $vessel_post->post_title;
  $vessel_imo = $vessel_meta->wpcf-imo;
  $vessel_type_specific = $vessel_meta->wpcf-type_specific;

  vsl_debug_log("Vessel image____");
  vsl_debug_log($image_height . $image_width);
  vsl_debug_log("Vessel name: " . $vessel_name);
  vsl_debug_log("Vessel IMO: " . $vessel_imo);
  vsl_debug_log("Vessel Type specific: " . $vessel_type_specific);
  

  //Get vessel image link from cloudinary
  $vessel_image_uri = vsl_vesselImage1($vessel_imo, '', $image_width, $image_height, 'img_uri', '1');
  vsl_debug_log(" Vessel image uri : " . $vessel_image_uri);
  $vessel_image_tag = "<img src='{$vessel_image_uri}' alt='{$vessel_name} ({$vessel_type_specific}) - IMO: {$vessel_imo} | Ship'>";
  vsl_debug_log(" Vessel image tag : " . $vessel_image_tag);
  return $vessel_image_tag;
}

I can see now the image is rendered using the custom shortcode. hidden link

It seems the code is called too soon before the custom code that is added to custom code section is enqueued.

#2117959

My issue is resolved now. Thank you!

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