Sunday 20 August 2017

Get html form post value in same page in php file

Here is the working code for Get html form post value in same page in php file:


<?php    
 if(isset($_POST['button'])){ //check if form was submitted
 $pohlavie = $_POST['gender']; //get input text
 $plat = $_POST['salary']; //get input text
 echo "Your gender is ".$pohlavie." and your salary is ".$plat;
 }    
 ?>

<center><h1>TAXES</h1></center>
<form action="" method="post">
Name: <input type="text" name="name"><br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="male"> Male<br>
Salary: <input type="number" name="salary"><br>
<button type="submit" name="button" formmethod="post">Calculate DPH</button>
</form>

Auto Play Youtube Video on Page load or in open bootstrap pop up

Here is the working code for Auto Play Youtube Video on Page load or in open bootstrap pop up:

<script type="text/javascript" src="https://www.youtube.com/player_api"></script>
 <script>

 // 2. This code loads the IFrame Player API code asynchronously.

// 3. This function creates an <iframe> (and YouTube player)
//    after the API code downloads.
var player;
// 5. The API calls this function when the player's state changes.
         //    The function indicates that when playing a video (state=1),
        //    the player should play for six seconds and then stop.
         var done = false;
 function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING && !done) {
          setTimeout(stopVideo, 6000);
          done = true;
        }
        }
       function onYouTubePlayerAPIReady() {
       player = new YT.Player('player', {
       height: '180',
       width: '640',
       videoId: 'JcO-vyfs_nc', //youtube video id
       playerVars: { autoplay: 1 },
                    events: {
                        'onReady': onPlayerReady,
                        'onStateChange': onPlayerStateChange
                    }
                });
            }
       function onPlayerReady(event) {
               event.target.setVolume(100);
        event.target.playVideo();

            }
            function stopVideo() {
                player.stopVideo();
            }

//video
 </script>

Add select class to ul li when click on it with jquery

Here is the working code for Add select class to ul li when click on it with jquery

<ul id="filters">
    <li> <a class="selected" data-filter="*"></a> All <li>
    <li> <a data-filter=".nokia"></a> Nokia <li>
    <li> <a data-filter=".samsung"></a> Samsung <li>
</ul>
 $("#filters li").click(function()
 {
 $("#filters li").removeClass("selected");
 $(this).addClass("selected");
 });

How to get parent page id and title of current page(child page) in wordpress?

Here is the code for  get parent page id and title of current page(child page) in wordpress?

global $post;
echo $post->post_parent;

If condition to check custom post type single page in wordpress

Here is the code to check If condition for custom post type single page

is_singular('people')

Wordpress Posts with multiple meta fields and values

Here is the code Wordpress Posts with multiple meta fields and meta values:


$meta = array();

if (isset($_GET['location'][0]) && !empty($_GET['location'][0])) {
            // restrict
   $meta[] = array(
    'key' => 'location',
    'value' => $_GET['location'][0] ,
'compare' => 'LIKE');

}
if (isset($_GET['language'][0]) && !empty($_GET['language'][0])) {
    $meta[] = array(
    'key' => 'language',
    'value' => $_GET['language'][0],
'compare' => 'LIKE');

}
if (isset($_GET['pr_area'][0]) && !empty($_GET['pr_area'][0])) {
    $meta[] = array(
    'key' => 'pr_area',
    'value' => $_GET['pr_area'][0],
'compare' => 'LIKE');

}
if (isset($_GET['keywords'][0]) && !empty($_GET['keywords'][0])) {
    $meta[] = array(
    'key' => 'keywords',
    'value' => $_GET['keywords'][0],
'compare' => 'LIKE');

}


$args = array( 'post_type' => 'people', 'orderby' => 'title','order' => ASC, 'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR', $meta));

    $loop = new WP_Query( $args );

Simple Custom Plugin In Wordpress

Here is the code for Simple Custom Plugin In Wordpress

/*
Plugin Name: Custom Plugin
Description: A very basic test plugin
Version: 1.0
Author: Ajay Malhotra
*/

function add_bottom_content( $content ) {
$content .= "Your Reviews On ".get_the_title().", Please!";
return $content;
}

add_filter( 'the_content', 'add_bottom_content' );

Add Php mysql data in Excel file

Here is code to add Php mysql data in Excel file:

require_once 'PHPExcel\Classes\PHPExcel.php';
$servername = "localhost";
$username = "root";
$password = "";

// Create connection
$conn = new mysqli($servername, $username, $password, "oops");

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";


$sql = "SELECT * FROM user";
$result = $conn->query($sql);
$objPHPExcel = new PHPExcel();
$row = 1;
while($subrow = $result->fetch_array())
{
$row++;
    $objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $subrow['id']);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$row, $subrow['name']);
$objPHPExcel->getActiveSheet()->setCellValue('c'.$row, $subrow['phone']);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$row, $subrow['email']);

 

}
$excelWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$excelWriter->save('userdata.xlsx');

Google Map Filter Api Example

Here is Google Map Filter Api Example: