Skip to content

Instantly share code, notes, and snippets.

Avatar

Navnit Viradiya navnit-viradiya

View GitHub Profile
@navnit-viradiya
navnit-viradiya / countries.js
Created Aug 21, 2018
List of Countries with Phone Code as a jQuery Array
View countries.js
var countries = {
"297" : {
"countryName": "Aruba",
"code": "AW",
"phoneCode": "297"
},
"93" : {
"countryName": "Afghanistan",
"code": "AF",
"phoneCode": "93"
@navnit-viradiya
navnit-viradiya / show-category-wise-posts-shortcode.php
Created Aug 28, 2018
Show category wise posts for custom post type in wordpress
View show-category-wise-posts-shortcode.php
<?php
//Show post category wise shortcode [show_post_category_wise]
add_shortcode('show_post_category_wise','show_post_category_wise_shortcode');
function show_post_category_wise_shortcode(){
$terms = get_terms('technology');
$html = '';
if($terms) {
foreach($terms as $term){
View show-category-wise-posts-shortcode.php
<?php
//Show post category wise shortcode [show_post_category_wise]
add_shortcode('show_post_category_wise','show_post_category_wise_shortcode');
function show_post_category_wise_shortcode(){
$terms = get_terms('category');
$html = '';
if($terms) {
foreach($terms as $term){
@navnit-viradiya
navnit-viradiya / character-limit.php
Created Aug 30, 2018
Set character limit on get_the_content() or get_the_excerpt() in wordpress
View character-limit.php
<?php
function break_content($text,$length){
$text = trim($text);
if(strlen($text)<$length+10)
return $text;//don't cut if too short
$break_pos = strpos($text, ' ', $length);//find next space after desired length
$visible = substr($text, 0, $break_pos);
@navnit-viradiya
navnit-viradiya / faq-example.html
Created Sep 7, 2018
FAQ Page with Show and Hide Questions and Answers. Showing First Question Answer on Page Load.
View faq-example.html
<!DOCTYPE html>
<html>
<head>
<title>faq</title>
<style>
/*FAQS*/
.faq_question {
@navnit-viradiya
navnit-viradiya / wp-query-with-meta-query.php
Created Sep 27, 2018
Wp_query example for meta query with multiple meta field.
View wp-query-with-meta-query.php
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
/*'meta_key' => 'ingredients',
'meta_value' => ' ',
'meta_compare' => '!='*/
'meta_query' => array(
'relation' => 'AND',
View wp-query-with-custom taxonomy.php
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array (
'taxonomy' => 'product_cat',
'field' => 'slug',
@navnit-viradiya
navnit-viradiya / wp-query-with-meta-query-and-taxonomy.php
Created Sep 27, 2018
WooCommerce search products between price range using WP_Query
View wp-query-with-meta-query-and-taxonomy.php
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array (
'taxonomy' => 'product_cat',
'field' => 'slug',
@navnit-viradiya
navnit-viradiya / functions.php
Created Apr 16, 2019
Get the right prev/next post link when order posts by menu_order
View functions.php
<?php
function my_previous_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order < %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
}
add_filter( 'get_previous_post_where', 'my_previous_post_where' );
function my_next_post_where() {
global $post, $wpdb;
return $wpdb->prepare( "WHERE p.menu_order > %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
@navnit-viradiya
navnit-viradiya / functions.php
Created Apr 30, 2019
WooCommerce - Add a special field to the checkout, order emails and user/order meta or Load specific custom fields on change country.
View functions.php
<?php
add_action('woocommerce_review_order_before_payment', 'gst_checkout_field');
function gst_checkout_field( $checkout ) {
echo '<div id="gst_checkout_field_sec">';
woocommerce_form_field( 'gst_no', array(
'type' => 'text',
'class' => array('my-field-class orm-row-wide'),
'label' => __('GST No'),