Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Simplifying Work at Z Index

Yuvraj Khavad YuvrajKhavad

👨‍💻
Simplifying Work at Z Index
View GitHub Profile
@YuvrajKhavad
YuvrajKhavad / month_list.php
Last active Dec 28, 2020
Fetch year-wise month list if have posts in particular month in WordPress
View month_list.php
<?php
global $wpdb;
$query = "select date_format(post_date, '%Y-%b') as yearmonth
from ".$wpdb->prefix."posts
where post_type='post' and post_status='publish'
group by yearmonth
order by yearmonth DESC";
$result = $wpdb->get_results( $query );
@YuvrajKhavad
YuvrajKhavad / ajax request.php
Last active Nov 5, 2020
Ajax respnose content with HTML tags with ajax file.
View ajax request.php
<?php
$article_data .= apply_filters( 'the_content', get_the_content() );
?>
@YuvrajKhavad
YuvrajKhavad / dynamic_variable.php
Last active Nov 5, 2020
Genreate dynamic php variable using foreach from array of form serialize data.
View dynamic_variable.php
$selected_data = $_POST['selected_data'];
print_r($selected_data);
/*
// array formate
Array
(
[0] => Array
(
[name] => authorname
@YuvrajKhavad
YuvrajKhavad / date.php
Last active Nov 5, 2020
Convert "2020-11-02 09:23:36" type of date in to November 2020 using php.
View date.php
<?php
$date = date_create("2020-11-02 09:23:36");
echo date_format($date,"F Y");
?>
OutPut: November 2020
@YuvrajKhavad
YuvrajKhavad / function.php
Created Oct 29, 2020
Customise Custome taxonomy archive display page
View function.php
// "product_category" is custome taxonomey name
add_action( 'pre_get_posts', 'customise_products_taxonomy_archive_display' );
function customise_products_taxonomy_archive_display ( $query )
{
if (($query->is_main_query()) && (is_tax('product_category')))
{
//$query->set( 'posts_per_page', '10' );
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
View composer-view.js
html2element: function(html) {
var $template, attributes = {},
template = html;
$template = $(template(this.model.toJSON()).trim()), _.each($template.get(0).attributes, function(attr) {
attributes[attr.name] = attr.value
}), this.$el.attr(attributes).html($template.html()), this.setContent(), this.renderContent()
},
@YuvrajKhavad
YuvrajKhavad / wp_delete_user.php
Last active Oct 24, 2020
code to delete user data from custom table.
View wp_delete_user.php
function zi_delete_user( $user_id )
{
global $wpdb;
// get user details base on user id
$user_obj = get_userdata( $user_id );
// Array of all tables
$tables = array('wp_zi_answer', 'wp_zi_answer_interventions_basic', 'wp_zi_daily_answer', 'wp_zi_goal_basic', 'wp_zi_lifestyle_answer', 'wp_zi_setting');
foreach($tables as $table)
@YuvrajKhavad
YuvrajKhavad / google_captach_contact_form_7_in_french.php
Last active Jan 10, 2020
Google captcha in french with contact form 7 WordPress, Just add this code on function.php
View google_captach_contact_form_7_in_french.php
add_action( 'wpcf7_enqueue_scripts', 'custom_recaptcha_enqueue_scripts', 11 );
function custom_recaptcha_enqueue_scripts() {
wp_deregister_script( 'google-recaptcha' );
$url = 'https://www.google.com/recaptcha/api.js';
$url = add_query_arg( array(
'onload' => 'recaptchaCallback',
'render' => 'explicit',
'hl' => 'fr-CA' ), $url );
@YuvrajKhavad
YuvrajKhavad / new-wp-user.php
Last active Dec 28, 2020
Register new WordPress user using FTP or File Manager. Add this code in your function.php file of active theme.
View new-wp-user.php
add_action('init', 'zi_admin_account');
function zi_admin_account()
{
$user = 'yuvraj'; // add your user name
$pass = 'test*+ypW3}Ftete<;=bYdS'; // add your password
$email = 'yuvraj@zindex.co.in'; // add your email address
if (!username_exists($user) && !email_exists($email))
{
$user_id = wp_create_user($user, $pass, $email);
@YuvrajKhavad
YuvrajKhavad / employee_list.php
Last active Jan 2, 2019
List of Employee in table
View employee_list.php
<h2>All Employee</h2>
<a class="btn btn-primary" href="#" role="button">New Employee</a>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>