Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
LinzardMac / filtered-facet.php
Last active February 5, 2023 08:37
FacetWP Customized Loop for "dates span" field type
function facet_availability_logic( $return, $params ) {
// get facet in question
$facet = $params['facet'];
// assign values to $selected_values var
$selected_values = $params['selected_values'];
// if the facet's NAME is 'date'
// (this can be changed to the name of your facet you want to override)
if ( 'dates' == $facet['name'] ) {
// assign variables to first (start date) and second (end date) queries passed
@LinzardMac
LinzardMac / gist:5b18ace5b2427f72c307
Created October 30, 2015 20:40
is_single() and is_singular() not running the filter on the queried object
/*
* Test case #1
*/
add_filter( 'the_title', 'my_add_custom_content' );
function my_add_custom_content( $title) {
if ( is_singular( 'events' ) ):
$postID = get_the_ID();
$html = '<a href="#" class="goingLink setGoing" id="'.$postID.'" data-value="'. $postID .'">I\'m Going</a><div id="fb-root"></div>';
function my_debug_tests( $data, $post, $context ) {
var_dump($data);
var_dump($post);
var_dump($context);
add_filter( 'json_prepare_post', 'my_debug_test', 10, 3 );
'meta_query' => array(
array(
'key' => 'tagged_users',
'value' => 's:1:"2";',
'compare' => 'IN',
),
Actual DB record:
a:1:{i:0;s:1:"2";}
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
if ( 'post' == get_post_type() && is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( 6, 1, $content );
}
}
$db = @mysql_connect('server', 'username', 'password');
if (!$db) echo "connection failed";
else echo "connection succeeded";
foreach($users as $user) {
$tagged_user_photos = get_user_meta($user, 'tagged_photos', false);
var_dump($tagged_user_photos);
$tagged_user_photos[] = $post_id;
update_user_meta( $user, 'tagged_photos', $tagged_user_photos);
}
_.each( this.$el.serializeArray(), function( pair ) {
/*
* Feature Added: returns js array object for multiple value inputs
* This is the reason we had to override the default save function
* function originates in media-views.js line 2295
*/
// if the pair.name is greater than 2 chars and [] is the last two chars
if ( pair.name.length > 2 && '[]' == pair.name.substr( pair.name.length - 2 ) ) {
@LinzardMac
LinzardMac / upload-media.js
Created August 14, 2015 18:43
Override BackBone attachment.Compat save function & bind select2
jQuery(document).ready(function($){
wp.media.view.AttachmentCompat.prototype.save = function( event ) {
var data = {};
if ( event ) {
event.preventDefault();
}
_.each( this.$el.serializeArray(), function( pair ) {
/* backbone functions for views */
render: function() {
var compat = this.model.get('compat');
if ( ! compat || ! compat.item ) {
return;
}
this.views.detach();
this.$el.html( compat.item );
this.views.render();