logo
down
shadow

How to use if condition in my wordpress shortcode


How to use if condition in my wordpress shortcode

By : joasda
Date : November 22 2020, 10:56 AM
this one helps. I think you are trying to check client name and company name if they are given from the back end. These fields are optional and you need to show those fields in your page only if there are some values there.
Please check with this code. This should help you:
code :
function testimonial_content_shortcode($atts){
  extract( shortcode_atts( array(
    'category' => '',
    'count' => '',
    'type' => 'post',
  ), $atts  ) );

    $q = new WP_Query(
        array('posts_per_page' => $count, 'post_type' => 'testimonial-items', 'order', 'ASC' )
        );    

  $list = '<div class="col-md-6 wow fadeIn belal_all_testimonial" data-wow-duration="0.6s" data-wow-delay="0.3s">';

  while($q->have_posts()) : $q->the_post();
     $idd = get_the_ID();
     $client_name = get_post_meta($idd, 'client_name', true);
     $company_name = get_post_meta($idd, 'company_name', true);

    $list .= '

            <div id="testimonial-'.$idd.'" class="testimonail-detail">
            <p>
            '.get_the_content().'
            </p>
            <div class="testimonial-info">';

if( !empty($client_name) ) {

         $list .= '<span class="company">
              Client Name:
            </span><span class="name">
                 '.$client_name.'
              </span>';
}
if( !empty($company_name) ) {
         $list .= '<span class="company">
              Company Name:
            </span>
              <span class="name">
                 '.$company_name.'
              </span>';
}

$list .= '</div>
          </div>';

  endwhile;
  $list.= '</div>';
  wp_reset_query();
  return $list;
}
add_shortcode('tcontent', 'testimonial_content_shortcode');


Share : facebook icon twitter icon
How add condition in wordpress shortcode loop

How add condition in wordpress shortcode loop


By : user3290365
Date : March 29 2020, 07:55 AM
this will help I want to multiple of 2 close div and open a new div in wp loop using shortcode post loop. , Based on your comment, maybe this helps:
code :
function testimonial_thumb_shortcode($atts){
    extract(shortcode_atts(array(
        'category' => ''
    ), $atts));
    $q = new WP_Query(array(
        'posts_per_page' => -1,
        'post_type' => 'testimonials',
        'testimonial_cat' => $category
    ));
    $list = ' <ul><li>';

    $i = 0; //init the counter

    while($q->have_posts()):
        $q->the_post();
        $idd = get_the_ID();
        $author_photo = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
        $list .= '/*Main loop*/';

        $i++; //increase counter
        if($i % 2 == 0){
            $list .= '</li><li>';
        }

    endwhile;
    $list.= '</li></ul>';
    wp_reset_query();
    return $list;
}
add_shortcode('tthumb', 'testimonial_thumb_shortcode');
Putting a wordpress shortcode inbetween another wordpress shortcode

Putting a wordpress shortcode inbetween another wordpress shortcode


By : kqf-bcd
Date : March 29 2020, 07:55 AM
it should still fix some issue From the Codex on nesting shortcodes:
code :
[tag-a]
   [tag-b]
      [tag-c]
   [/tag-b]
[/tag-a]
[tag-a]
   [tag-a]
      [tag-c]
   [/tag-a]
[/tag-a]
Shortcode inside shortcode of CF7DB-extention (Wordpress Contact form 7 to database plugin)

Shortcode inside shortcode of CF7DB-extention (Wordpress Contact form 7 to database plugin)


By : piano forte
Date : March 29 2020, 07:55 AM
I hope this helps . Is there a way to use a shortcode inside the CF7DB shortcodes (Wordpress plugin)? , try this:
code :
$email = do_shortcode("[user_email]");
echo do_shortcode('[cfdb-table form="Registration 3GC" search="'. $email .'"]');
Display WordPress page content with shortcode and show embedded shortcode

Display WordPress page content with shortcode and show embedded shortcode


By : Mikey Keenan
Date : March 29 2020, 07:55 AM
it should still fix some issue I'm using a Custom Post Type to display banners on my site. The content could be text, images and also shortcodes (e.g. a button shortcode). , Try below code:
code :
// [banner id="" class=""]
function shortcode_banner( $atts, $content ) {
    extract(shortcode_atts( array(
        'id'    => '',
        'class' => '',
    ), $atts ) );

    $banner_id = $id;
    $content   = get_post_field( 'post_content', $banner_id );

    return '<div class="'.$class.'">'.wpautop( do_shortcode( $content ) ).'</div>';
}
function recursively_do_shortcode( $content ) {
    $content2 = $content;
    do{
       $content = $content2;
       $content2 = do_shortcode( $content );
    } while( $content2 !== $content ); // presumably you can test if shortcodes exist in content as well
    return $content2;
}

// [banner id="" class=""]
function shortcode_banner( $atts, $content ){
    extract( shortcode_atts( array(
        'id'    => '',
        'class' => '',
    ), $atts ) );

    $banner_id = $id;
    $content   = get_post_field( 'post_content', $banner_id );

    return '<div class="'.$class.'">'.wpautop( recursively_do_shortcode( $content ) ).'</div>';
}
page not updating when adding shortcode and it is rendering the shortcode content in wordpress dashboard also during wor

page not updating when adding shortcode and it is rendering the shortcode content in wordpress dashboard also during wor


By : user3502340
Date : March 29 2020, 07:55 AM
around this issue I am developing a wordpress plugin for event slider , but when i add shortcode to display the slider the wordpress page editor doesnot update and it is also rendering the content in admin dashboard. the error i am getting is "Updating failed. Error message: The response is not a valid JSON response." ,
Change your shortcode to
code :
add_shortcode("myeventplugin","short_code_view");
function short_code_view(){
    ob_start();
    include PLUGIN_DIR_PATH.'views/shortcode-template.php';
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
Related Posts Related Posts :
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • What's wrong with my PHP Script? T_String issue
  • how to call a function of another file without including that file
  • is_rgb function in php
  • transform the numbers to letters using php
  • How to catch an exception from another class method PHP
  • PHP exec is blocked by ISP
  • PHP4 to PHP5 migration character encoding. latin1 vs utf8
  • Begin Transaction not defined
  • How much harm can a user do with xss on a page unique to them?
  • How to import data from a php file to javascript variable
  • PHP and Javascript - log complete workflow
  • When I echo !!! 0 it gives me a strange result
  • jquery ajax post dies after submit
  • How to upload file with curl on sftp server
  • Advanced search using a text input to search through only one category
  • Why do I get "Non-static method App\Models\Category::products() should not be called statically" in laravel
  • Stop notices from undefined indexes in arrays
  • PHP Excel Error when entering SUM function to a cell
  • laravel 4 eloquent eager load relation count
  • click submit in html and run php code
  • Extremely frustrating behavior with Internet Explorer, Bootstrap and Respond.js
  • Vkontakte vtag issues
  • Divide the number to a correct decimal
  • mysqli_insert_query not working
  • How to make a sitemap using zend framework 1
  • Laravel: array to Model with relationship tree
  • $_SERVER['DOCUMENT_ROOT'] vs $path = $_SERVER['DOCUMENT_ROOT']
  • What is the best way to store multiple checkbox values in the database and work with it later on
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org