Skip to content

Instantly share code, notes, and snippets.

View dospuntocero's full-sized avatar

Francisco arenas dospuntocero

View GitHub Profile
@dospuntocero
dospuntocero / add sort order on wordpress
Last active May 31, 2019 02:08
combination of parts needed to add a new parameter on the wordpress url for sorting.
<?php
//adds the orderby parameter to the url for the sorting
function add_orderby() {
if ( isset( $_GET['orderby'] ) ) {
if ( in_array( $_GET['orderby'],[]) ) {
set_query_var( 'orderby', 'meta_value_num' );
set_query_var( 'meta_key', $_GET['orderby'] );
}
}
@dospuntocero
dospuntocero / singlefield.php
Last active May 31, 2019 02:09
solution found on advanced custom fields support forum. kudos to EbbandFlow
<?php
//For use with a single field.
$video = get_field('video'); //Embed Code
$video_url = get_field('video', FALSE, FALSE); //URL
$video_thumb_url = get_video_thumbnail_uri($video_url); //get THumbnail via our functions in functions.php ?>
<?php //Lightbox Link via Thumbnail ?>
<a href="#lightbox"><img src="<?php echo $video_thumb_url; ?>"/></a>
@dospuntocero
dospuntocero / youtube-id.php
Created March 3, 2019 20:59 — forked from leogopal/youtube-id.php
PHP function to get youtube ID from URL
<?php
function get_youtube_video_ID($youtube_video_url) {
/**
* Pattern matches
* http://youtu.be/ID
* http://www.youtube.com/embed/ID
* http://www.youtube.com/watch?v=ID
* http://www.youtube.com/?v=ID
* http://www.youtube.com/v/ID
* http://www.youtube.com/e/ID
@dospuntocero
dospuntocero / multiposttype
Created February 27, 2019 00:10
Query multiple custom post types in single loop
<?php
$args = array(
'post_type' => array('testimonial', 'other_post_type', 'another-post-type'),
'posts_per_page' => 1,
'tax_query' => array(
array (
'taxonomy' => 'testimonial_category',
'field' => 'slug',
'terms' => 'home'
)
@dospuntocero
dospuntocero / generic post type loop
Last active May 31, 2019 02:09
generic post type loop
<?php
$loop = new WP_Query( array(
'post_type' => 'the post type',
'posts_per_page' => -1
)
);
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
@dospuntocero
dospuntocero / extend image
Created February 24, 2019 16:44
used this technique to expand an image to fill the whole div and maintain aspect ratio
.full-image-div{
width:100%;
height:100%;
object-fit: cover;
overflow: hidden;
}
@dospuntocero
dospuntocero / videolink id
Created February 24, 2019 14:12
i need to get just the id from a youtube link using an oembed field from advanced custom fields
@dospuntocero
dospuntocero / excerpt_limit.php
Created November 19, 2018 01:24
Limit the excerpt by number of characters but do NOT truncate the last word. This will allow you to return a maximum number of characters but preserve full words, so only the words that can fit within the specified number limit are returned and allow you to specify the source of where the excerpt will come from.
function get_excerpt($limit, $source = null){
$excerpt = $source == "content" ? get_the_content() : get_the_excerpt();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $limit);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = $excerpt.'... <a href="'.get_permalink($post->ID).'">more</a>';
@dospuntocero
dospuntocero / remove editor
Created September 9, 2018 18:26
remove plain editor from wordpress waiting for guttenberg support on pages
function hide_editor() {
remove_post_type_support('page', 'editor');
}
add_action( 'admin_init', 'hide_editor' );
@dospuntocero
dospuntocero / even odd inside foreach example
Created September 9, 2018 16:03
use this if you need a foreach with even/odd classes
<?php
$recent_posts = wp_get_recent_posts();
?>
<?php $current_class = 'odd';?>
<?php foreach( $recent_posts as $recent ):?>
<?php $current_class = ($current_class == 'odd') ? 'even' : 'odd'; ?>
<div class="<?php echo $current_class ?>">
<?php echo $recent["post_title"]?>
<a href="<?php echo get_permalink($recent["ID"])?>">READ MORE</a>