Top Questions

  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : Mar 15, 2018

    You can specify a function identifier in a custom property in your .ajax() call and use the value of that in your ajaxComplete() callback.

    For example, get any ajax property while making your .ajax() call:
    function foo() {
        $.ajax({
            url: 'my-page.php',
        });
    }
    
    And then, use any of ajax property to ajaxComplete() like this:
    $('#my-unique-id').ajaxComplete(function(e, xhr, settings) { // run after all ajax complete 
        if (settings.url == 'my-page.php') { // write condition according to your requirement
            // execute you code
        } else {
            // execute you code
        }
    });
     
  • 5.11 Years

    • Category : Php
    • Location : Mohali
    • Posted On : Oct 7, 2017

    YouTube video Link may be encountered in a variety of formats:

    1.     latest short format: http://youtu.be/NLqAF9hrVbY
    2.     iframe: http://www.youtube.com/embed/NLqAF9hrVbY
    3.     iframe (secure): https://www.youtube.com/embed/NLqAF9hrVbY
    4.     object param: http://www.youtube.com/v/NLqAF9hrVbY?fs=1&hl=en_US
    5.     object embed: http://www.youtube.com/v/NLqAF9hrVbY?fs=1&hl=en_US
    6.     watch: http://www.youtube.com/watch?v=NLqAF9hrVbY
    7.     users: http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo
    8.     ytscreeningroom: http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I
    9.     any/subdomain/too: http://gdata.youtube.com/feeds/api/videos/NLqAF9hrVbY
    10.     more params: http://www.youtube.com/watch?v=spDj54kf-vY&feature=g-vrec
    11.     query may have dot: http://www.youtube.com/watch?v=spDj54kf-vY&feature=youtu.be
    12.     nocookie domain: http://www.youtube-nocookie.com
    function convertYoutube($string) {
    	$pattern='~(?#!js YouTubeId Rev:20160125_1800)
            # Match non-linked youtube URL in the wild. (Rev:20130823)
            https?://          # Required scheme. Either http or https.
            (?:[0-9A-Z-] \.)?  # Optional subdomain.
            (?:                # Group host alternatives.
              youtu\.be/       # Either youtu.be,
            | youtube          # or youtube.com or
              (?:-nocookie)?   # youtube-nocookie.com
              \.com            # followed by
              \S*?             # Allow anything up to VIDEO_ID,
              [^\w\s-]         # but char before ID is non-ID char.
            )                  # End host alternatives.
            ([\w-]{11})        # $1: VIDEO_ID is exactly 11 chars.
            (?=[^\w-]|$)       # Assert next char is non-ID or EOS.
            (?!                # Assert URL is not pre-linked.
              [?=& %\w.-]*     # Allow URL (query) remainder.
              (?:              # Group pre-linked alternatives.
                [\'"][^<>]*>   # Either inside a start tag,
              | </a>           # or inside <a> element text contents.
              )                # End recognized pre-linked alts.
            )                  # End negative lookahead assertion.
            [?=& %\w.-]*       # Consume any URL (query) remainder.
            ~ix';
    	preg_match_all($pattern,$string,$match);
    	$res=array();
    	$res['youtube']=$match;
    	$res['text']=preg_replace($pattern, '', $string);
    	return $res;
    }
    $text = "php find youtube link in string. How do I find all YouTube video ids in a string using a regex https://www.youtube.com/watch?v=ItTjUrTZ_JE Find youtube Link in PHP string and Convert it into embed code? Well, you need to filter out the youtube links first and put them into an string. Next you need to find out the youtube links of the url which is very easy. Use this script:";
    
    $all=convertYoutube($text);
    
    //print_r($all);
    
    echo $all['youtube'][1][0];	
    // ItTjUrTZ_JE
    
    echo $all['youtube'][0][0];	
    // https://www.youtube.com/watch?v=ItTjUrTZ_JE
    
    echo $all['text'];	
    // php find youtube link in string. How do I find all YouTube video ids in a string using a regex Find youtube Link in PHP string and Convert it into embed code? Well, you need to filter out the youtube links first and put them into an string. Next you need to find out the youtube links of the url which is very easy. Use this script:
    
  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Feb 25, 2016
    $(function(){
        // this will get the full URL at the address bar
        var url = window.location.href; 
        // passes on every "a" tag 
        $(".main-nav li a").each(function() {
                // checks if its the same on the address bar
            if(url == (this.href)) { 
                $(this).closest("li").addClass("current");
            }
        });
    });

     

  • 2.9 Years

    • Category : Jquery
    • Location : Chandigarh
    • Posted On : Feb 27, 2017

    using this code you can prevent required values in html5

    <script src="https://cdnjs.cloudflare.com/ajax/libs/webshim/1.16.0/dev/polyfiller.js" type="text/javascript"></script>
    
    <script> 
            webshim.activeLang('en');
            webshims.polyfill('forms');
            webshims.cfg.no$Switch = true;
    </script>
     
  • 2.9 Years

    • Category : Php
    • Location : Chandigarh
    • Posted On : Dec 23, 2015
    <form action="" method="post" enctype="multipart/form-data" class="upload_bus"> 
    div class="btn-group col-lg-3 col-md-3 col-sm-6 col-xs-12 rightgp-btns">
      <input class="create-doc" id="upbuss"  type="file" name="upbus" >
    </div>
    </form>
    <center><div id="loader-icon" style="display:none;"><img src="images/loader-time.gif" height="100px" width="100px" /></div></center>
    <script>
    $('input#upbill').change(function(){
    $('form.upload_b').submit();
    })
    $('form.upload_b').submit(function(e){
      var formData = new FormData(this);
      $('#loader-icon').show();
    $.ajax({
    url: "upload_file.php",            
    type: "POST",
    data:  formData,
    mimeType:"multipart/form-data",
    contentType: false,
    cache: false,
    processData:false,
    success: function(data)
    {
      $('#loader-icon').hide();
       window.location.href="example.php";
    }
    });
    return false;
    });
    </script>

     

  • 2.9 Years

    • Category : Ajax
    • Location : Chandigarh
    • Posted On : Apr 25, 2016

    print your custom data or field using ajax

    function printinvoice(id){
         $.ajax({
           url: "sample.php",            
                type: "POST",
           data: "print_id=" id,
          success: function(data) {
         newWin= window.open();
                            newWin.document.write(data);
                            newWin.document.close();
                            newWin.focus();
                            newWin.print();
                             newWin.close();
          },
      error: function() {
         
          }
       }); 
    }
  • 0.0 Years

    • Category : Wordpress
    • Location : Unknown
    • Posted On : Mar 22, 2016

    Get Posts By Sub Category ID in Wordpress.

    <?php query_posts('cat=10&showposts=-1');
               $posts = get_posts('category=10&numberposts=3&offset=0');
                foreach ($posts as $post) : start_wp(); ?>
    
                <?php $cats = get_the_category($post->ID);
                $subcategories = array();
                foreach( $cats as $cat ) {
                $subcats = get_categories('child_of='.$cat->term_id);
                if($subcats) {
                foreach( $subcats as $subcat )
                {  $subcategories[] = sanitize_title($subcat->name); }
                }
                }
                $subcats = array_unique($subcategories);
                if($subcats) {
                $subcats = implode(' ',$subcats);
                $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
               // echo '<li class="' . $subcats . '">';
    
                }
                ?>
                    <figure class="mix portfolio-item print">
                        <img class="img-responsive" src="<?php echo $url; ?>" alt="Portfolio Item">
                        <a href="<?php echo $url; ?>" title="Title Four" rel="portfolio" class="fancybox"><span class="plus"></span></a>
                        <figcaption class="mask">
                            <h3><?php the_title(); ?></h3>
                            <span><?php the_content(); ?></span>
                        </figcaption>
                    </figure>
    
    <?php endforeach ?>
    
  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : May 29, 2018

    default WooCommerce if the user clicks on the add to cart button, that item is added to the cart. if you want to add custom add to cart button please remove default "add to cart" button

    // custom template
    <button type="submit" class="custom_cart_button">add to cart</button>
    <script type="text/javascript">
    jQuery(document).ready(function() {
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
        jQuery('.custom_cart_button').submit(function(e) {
            jQuery.ajax({
                url: ajaxurl,
                type: "post",
                data: {				
    		action : 'post_product_variations19'
    	    },
                success: function(data) {   
                	console.log(data);
                }
            });
    	return false;
        });
    });
    </script>
    
    
    // function.php
    add_action( 'wp_ajax_nopriv_post_product_variations19', 'post_product_variations_func19' );
    add_action( 'wp_ajax_post_product_variations19', 'post_product_variations_func19' );
    function post_product_variations_func19() {
    
        global $woocommerce;
    
        $product_id = 364; // your product id
    
        $found = false;
    
        //check if product already in cart
        if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
            foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
                $_product = $values['data'];
                if ( $_product->id == $product_id ) {
                	//$calc_qty = $values['quantity'] < 1 ? 1 : $values['quantity']+1;
                	//$woocommerce->cart->set_quantity( $cart_item_key, $calc_qty, true );
                    $found = true;
                }
            }
            // if product not found, add it
            //if ( ! $found )
                $woocommerce->cart->add_to_cart( $product_id );
        } else {
            // if no products in cart, add it
            $woocommerce->cart->add_to_cart( $product_id );
        }
    	
    wp_die();
    }
  • 5.11 Years

    • Category : Css
    • Location : Mohali
    • Posted On : May 9, 2016

    this css class add your bootstrap modal then see the magic

    rotate {
        transform:rotate(180deg);
        transition:all 0.5s;
    }
    .rotate.in {
        transform:rotate(1800deg);
        transition:all 1.5s;
    }
  • 5.11 Years

    • Category : Wordpress
    • Location : Mohali
    • Posted On : Feb 22, 2018

    This action hook allows you to access data for a new user immediately after they are added to the database. The user id is passed to hook as an argument.

    add_action( 'user_register', 'eddpremium_register_fields_save');
    add_action( 'profile_update', 'eddpremium_register_fields_save');
    
    function eddpremium_register_fields_save($user_id) {
    	$u = new WP_User($user_id);
    
    	// Remove role
    	$u->remove_role( 'subscriber' );
    
    	// Add role
    	$u->add_role( 'author' );
    }