Skip to content

Instantly share code, notes, and snippets.

@gzalinski
gzalinski / buddyboss.php
Last active September 23, 2022 14:20
Buddyboss - Add Country Field
<?php
/**
* BuddyBoss Country Field
* Create and autocomplete dropdown "Country" field
* After the field has been created, delete this code
*/
function bp_add_custom_country_list()
{
@gzalinski
gzalinski / function.php
Created August 29, 2022 16:58
WP_Query: Posts between two meta date
global $wpdb;
$today_start = date('Y-m-d H:i:s', strtotime('yesterday 9pm'));
$today_end = date('Y-m-d H:i:s', strtotime('today 9pm'));
$SQL_ACF_TODAY = "SELECT $wpdb->posts.id FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta
ON $wpdb->postmeta.post_id = $wpdb->posts.ID
WHERE 1 = 1
AND $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_status = 'publish'
@gzalinski
gzalinski / functions.php
Last active August 16, 2022 05:02
Memberpress Signup - get forms by ajax
/**
* AJAX Custom Signup
*/
add_action('wp_ajax_es_mepr_signup_toggle_form', 'es_mepr_signup_toggle_form_callback');
add_action('wp_ajax_nopriv_es_mepr_signup_toggle_form', 'es_mepr_signup_toggle_form_callback');
function es_mepr_signup_toggle_form_callback()
{
@gzalinski
gzalinski / template.php
Created November 17, 2021 09:36
Woocommerce product query on sale between two date
<?php
$query_args = array(
'post_type' => [ 'product_variation', 'product' ],
'posts_per_page' => - 1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_sale_price_dates_from',
'value' => time(),
@gzalinski
gzalinski / script.js
Last active May 25, 2022 14:35
[jQuery catch ajax complete event] #js #snippet #ajax
$(document).ajaxComplete(function (event, xhr, settings) {
//if (!settings.url.includes('update_listing_account')) { return; }
if (typeof settings.data != 'object') { return }
if (settings.data.get('action') != 'update_listing_account') { return }
if (typeof xhr.responseText != 'undefined') {
const response = $.parseJSON(xhr.responseText)
}
});
@gzalinski
gzalinski / XC_ProductCategories.php
Created September 14, 2021 18:12
Get product categories with setting and display in list/menu/dropdown
<?php
/**
* Class XC_ProductCategories
* @usage $cat_list = new XC_ProductCategories();
* @usage $cat_list->render($attributes);
*/
class XC_ProductCategories {
public $defaults
@gzalinski
gzalinski / function.php
Created September 13, 2021 14:37
Address to geocode / coordinates
function geocode($address)
{
// url encode the address
$address = urlencode($address);
$apiKey = GMAP_API_KEY;
// google map geocode api url
$url = "https://maps.googleapis.com/maps/api/geocode/json?address={$address}&key={$apiKey}";
// get the json response
$resp_json = file_get_contents($url);
// decode the json
@gzalinski
gzalinski / SQL Run
Created September 13, 2021 13:13
SQL Delete Post Type
//Delete all POSTS META
DELETE
FROM `wp_postmeta`
WHERE post_id in (SELECT id
FROM `wp_posts`
WHERE `post_type` = 'post' )
//Delete all POSTS
DELETE FROM `wp_posts`
WHERE `post_type` = 'post'
@gzalinski
gzalinski / function.php
Created September 9, 2021 05:25
WP Upload Image from Front-End
<?php
/**
* Create the image attachment and return the new media upload id.
*
* @param $fileObject
* @return false|int|WP_Error
* @see http://codex.wordpress.org/Function_Reference/wp_insert_attachment#Example
* @since 1.0.0
*/
@gzalinski
gzalinski / function.php
Created August 27, 2021 15:41
Woocommerce Mini Cart with ajax count update
<?php
/**
* @title: WC Mini Cart
* @usage: echo do_shortcode( '[xcminicart]' );
*/
if ( ! class_exists( 'WooCommerce' ) ) {
return;
}