Skip to content

Instantly share code, notes, and snippets.

View YuvrajKhavad's full-sized avatar
👨‍💻
Simplifying Work at Z Index

Yuvraj Khavad YuvrajKhavad

👨‍💻
Simplifying Work at Z Index
View GitHub Profile
@YuvrajKhavad
YuvrajKhavad / gist:448fe24c56764ced103e17f0e9866182
Last active May 25, 2024 11:01 — forked from jaredatch/gist:7093295
Dynamically populate a submenu with posts
<?php
/**
* Adds the most recent "Some Category" posts as sub menu items under
* the "Some Category Parent" parent menu item.
*
* @param array $items
* @param array $menu
* @param array $args
* @return array
*/
@YuvrajKhavad
YuvrajKhavad / month_list.php
Last active December 28, 2020 04:15
Fetch year-wise month list if have posts in particular month in WordPress
<?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 November 5, 2020 12:33
Ajax respnose content with HTML tags with ajax file.
<?php
$article_data .= apply_filters( 'the_content', get_the_content() );
?>
@YuvrajKhavad
YuvrajKhavad / dynamic_variable.php
Last active November 5, 2020 07:20
Genreate dynamic php variable using foreach from array of form serialize data.
$selected_data = $_POST['selected_data'];
print_r($selected_data);
/*
// array formate
Array
(
[0] => Array
(
[name] => authorname
@YuvrajKhavad
YuvrajKhavad / date.php
Last active November 5, 2020 07:21
Convert "2020-11-02 09:23:36" type of date in to November 2020 using 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 October 29, 2020 12:29
Customise Custome taxonomy archive display page
// "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' );
}
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 October 24, 2020 12:17
code to delete user data from custom table.
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 January 10, 2020 11:47
Google captcha in french with contact form 7 WordPress, Just add this code on function.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 June 19, 2022 05:00
Register new WordPress user using FTP or File Manager. Add this code in your function.php file of active theme.
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);