Skip to content

Instantly share code, notes, and snippets.

View leoken's full-sized avatar

Erik James Albaugh leoken

  • Maintain Web
  • Long Beach, CA
  • X @leoken
View GitHub Profile
SELECT DISTINCT
post_title
, post_content
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Asking Price (US\$)' AND wp_postmeta.post_id = wp_posts.ID) as "Asking Price (US\$)"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Asking Price (ZAR)' AND wp_postmeta.post_id = wp_posts.ID) as "Asking Price (ZAR)"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Author' AND wp_postmeta.post_id = wp_posts.ID) as Author
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Binding' AND wp_postmeta.post_id = wp_posts.ID) as Binding
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Book Condition' AND wp_postmeta.post_id = wp_posts.ID) as "Book Condition"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Book Number' AND wp_postmeta.post_id = wp_posts.ID) as "Book Number"
,(SELECT meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = 'Book Type' AND wp_postmeta.post_id = wp_posts.ID) as "Book Type"
<?php
 
/*
* Loop through a Repeater field
*/
 
if( get_field('repeater') )
{
while( has_sub_field('repeater') )
{
<?php
 
/*
* Get a field object and display it with it's value
*/
 
$field_name = "text_field";
$field = get_field_object($field_name);
 
echo $field['label'] . ': ' . $field['value'];
<?php
/*
* Plugin Name: Mini Admin Bar
* Plugin URI: http://www.netyou.co.il/
* Description: Makes the admin bar a small button on the left and expands on hover.
* Version: 1.0
* Author: NetYou
* Author URI: http://www.netyou.co.il/
* License: MIT
* Copyright: NetYou
function cc_mime_types( $mimes ){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter( 'upload_mimes', 'cc_mime_types' );
<link href="touch-icon-iphone.png" rel="apple-touch-icon-precomposed" />
<link href="touch-icon-ipad.png" rel="apple-touch-icon-precomposed" sizes="72x72" />
<link href="touch-icon-iphone4.png" rel="apple-touch-icon-precomposed" sizes="114x114" />
<link href="touch-icon-ipad3.png" rel="apple-touch-icon-precomposed" sizes="144x144" />
@leoken
leoken / query-cat-and-key.php
Created October 19, 2013 20:58
Query by Category Name and Custom Field Key Sorted by Key's Value This example selects posts that have a common category name and custom field key, then sorts the selection by the custom key's value. From http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query
$querystr = "
SELECT * FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
WHERE $wpdb->terms.name = 'slides'
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
$querystr = "
SELECT $wpdb->posts.*
FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id)
WHERE $wpdb->postmeta.meta_key = 'paragraf'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
AND $wpdb->post2cat.category_id IN (1,2,3)
ORDER BY $wpdb->postmeta.meta_value ASC
@leoken
leoken / first-image.php
Created October 19, 2013 14:27
Show the first image associated with the post This function retrieves the first image associated with a post From http://codex.wordpress.org/Function_Reference/get_children#Examples
<?php
function echo_first_image( $postID ) {
$args = array(
'numberposts' => 1,
'order' => 'ASC',
'post_mime_type' => 'image',
'post_parent' => $postID,
'post_status' => null,
'post_type' => 'attachment',
);