Sunday, 20 August 2017

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: