Skip to content

Instantly share code, notes, and snippets.

@fomigo
fomigo / meta-fields-from-all-posts.php
Created June 19, 2015 07:12
how-to-get-a-meta-values-from-all-posts-in-a-special-category
<?php
// http://wordpress.stackexchange.com/questions/64338/how-to-get-a-meta-value-from-all-post
// https://wordpress.org/support/topic/how-to-get-a-meta-values-from-all-posts-in-a-special-category
function get_meta_values( $key = '', $type = 'post', $status = 'publish' ) {
if( empty( $key ) ) return;
global $wpdb;
$r = $wpdb->get_results( $wpdb->prepare( "
SELECT p.ID, pm.meta_value FROM {$wpdb->postmeta} pm
@fomigo
fomigo / wp-query-ref.php
Last active August 29, 2015 14:26 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@fomigo
fomigo / wpdb-queries-with-meta-data.php
Created August 8, 2015 14:48
wpdb queries with meta data
<?php
$results = $wpdb->get_results(
"
SELECT key2.meta_value as cat_id, $wpdb->posts.ID as action_id -- , $wpdb->posts.post_title as title
FROM $wpdb->posts
INNER JOIN $wpdb->postmeta key1
ON $wpdb->posts.ID = key1.post_id
INNER JOIN $wpdb->postmeta key2
ON $wpdb->posts.ID = key2.post_id
WHERE key1.meta_key = 'active'
@fomigo
fomigo / is_ajax.php
Created January 13, 2012 18:50
How to know it's an ajax request
<?php
$ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
@fomigo
fomigo / email_string_parsing.php
Created January 13, 2012 18:54
Example of parsing strings of emails
<?php
$string = 'first@mail.ru=From first||second@mail.ru=From second';
$mails = explode('||', $string);
$to = array();
foreach ($mails as $mail) {
list($key, $value) = explode('=', $mail);
$to[trim($key)] = trim($value);
}
@fomigo
fomigo / ajaxSetupForLoadingImage.js
Created January 13, 2012 18:58
How to control 'loading...' process in Ajax request
$(document).ready(function () {
/*************** FIRST EXAMPLE *********************/
$.ajaxSetup({
beforeSend: function() {
$('#general-ajax-load').fadeIn();
},
complete: function() {
$('#general-ajax-load').fadeOut();
},
@fomigo
fomigo / MODX Basic Template
Created February 3, 2012 16:49
MODX Basic Template extended
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>[[++site_name]] - [[*pagetitle]]</title>
<base href="[[++site_url]]" />
<style>
body {margin:auto; width:800px; color: #5F5F5F;}
</style>
</head>
@fomigo
fomigo / jquery.groupedAjax.js
Created February 17, 2012 11:35 — forked from Zoramite/jquery.groupedAjax.js
jQuery ajax grouping with Deferred objects.
(function($){
var requests = {};
$(function(){
// Determine which data you need and call the getData()...
// Stubbing in some example data...
// This is a unique request and would make an ajax call
getData({
foo: 'bar'
@fomigo
fomigo / jquery deferred
Created February 28, 2012 12:35
just one of the usage jquery deferred
$.when(
$.ajax('ajax.php')
).then(function(data){
// Here I can work with data like I would with a regular ajax request
alert($(data).find('mynode').text());
})
@fomigo
fomigo / SplClassLoader.php
Created March 10, 2012 05:51 — forked from jwage/SplClassLoader.php
SplClassLoader implementation
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.