Skip to content

Instantly share code, notes, and snippets.

@twentyfortysix
twentyfortysix / Custom wp_query
Last active March 12, 2016 17:39
WP - custom query
$out = '';
$page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'page',
'posts_per_page' => '100',
'paged' => $page
);
// The Query
$the_query = new WP_Query( $args );
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
@twentyfortysix
twentyfortysix / images on the fly
Last active February 13, 2016 19:51
WP - resize images on the fly
/*
* originally by http://core.trac.wordpress.org/ticket/15311
* updated for WP 3.5 by me, who else :)
* Resize images dynamically using wp built in functions
* Victor Teixeira
*
* php 5.2+
*
* Exemplo de uso:
*
@twentyfortysix
twentyfortysix / Post images
Last active February 13, 2016 19:51
WP - get post images
<?php global $post;
$g_args =array(
'post_parent' => $post->ID,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order'
);
@twentyfortysix
twentyfortysix / WP content mass cleaner.php
Last active February 13, 2016 19:51
WP - content cleaner
// cleaner
// credits http://wordpress.stackexchange.com/questions/52097/better-way-to-remove-html-syntax-from-all-content
$tochange = get_posts('post_type=product&numberposts=-1');
foreach ($tochange as $post):
setup_postdata($post);
$changed = array();
$changed['ID'] = $post->ID;
$changed['post_content'] = strip_tags($post->post_content, '<img><a>'); // post_excerpt
print_r($post->ID);
@twentyfortysix
twentyfortysix / Get ID by title (WP)
Last active February 13, 2016 19:50
WP - Get ID by title
function get_id_by_title($title){
global $wpdb;
$p = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = $title");
return $p;
}
@twentyfortysix
twentyfortysix / img
Last active February 13, 2016 19:50
WP - get featured img. src.
$img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
@twentyfortysix
twentyfortysix / responsive image
Last active August 29, 2015 14:08
WP function
// picture ids: array(1, 2, 3)
// $queries = array(
// array('large_screens','min-width: 1450px'),
// array('medium','max-width: 480px'),
// array('large','')
// );
// $class = class
function responsive_picture2($id, $class, $queries){
$with_euery = '';
$without_euery = '';
@twentyfortysix
twentyfortysix / responsive background images
Last active February 13, 2016 19:49
WP - alternative eresponsive background images
// picture ids: array(1, 2, 3)
// $queries = array(
// array('large_screens','min-width: 1450px'),
// array('medium','max-width: 480px'),
// array('large','')
// );
function responsive_background_pictures($id_array, $queries){
$with_euery = '';
$without_euery = '';
// for each style resolution
@twentyfortysix
twentyfortysix / register post type.php
Last active February 13, 2016 19:49
WP - register post type
<?php
add_action( 'init', 'register_my_post_type' );
/**
* Register a type post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function register_my_post_type() {
$labels = array(
'name' => _x( 'types', 'post type general name', 'your-plugin-textdomain' ),