Skip to content

Instantly share code, notes, and snippets.

Francisco arenas dospuntocero

Block or report user

Report or block dospuntocero

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dospuntocero
dospuntocero / multiposttype
Created Feb 27, 2019
Query multiple custom post types in single loop
View multiposttype
<?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
generic post type loop
View 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 Feb 24, 2019
used this technique to expand an image to fill the whole div and maintain aspect ratio
View extend image
.full-image-div{
width:100%;
height:100%;
object-fit: cover;
overflow: hidden;
}
@dospuntocero
dospuntocero / videolink id
Created Feb 24, 2019
i need to get just the id from a youtube link using an oembed field from advanced custom fields
View videolink id
@dospuntocero
dospuntocero / excerpt_limit.php
Created Nov 19, 2018
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.
View excerpt_limit.php
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 Sep 9, 2018
remove plain editor from wordpress waiting for guttenberg support on pages
View remove editor
function hide_editor() {
remove_post_type_support('page', 'editor');
}
add_action( 'admin_init', 'hide_editor' );
@dospuntocero
dospuntocero / even odd inside foreach example
Created Sep 9, 2018
use this if you need a foreach with even/odd classes
View even odd inside foreach example
<?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>
@dospuntocero
dospuntocero / even-odd for functions.php
Created Sep 9, 2018
add this function to your functions.php class and then add the filter to the result you need to have it.
View even-odd for functions.php
function oddeven_post_class ( $classes ) {
global $current_class;
$classes[] = $current_class;
$current_class = ($current_class == 'odd') ? 'even' : 'odd';
return $classes;
}
add_filter ( 'post_class' , 'oddeven_post_class' );
global $current_class;
$current_class = 'odd';
@dospuntocero
dospuntocero / even-odd.php
Created Sep 9, 2018
even odd classes on wordpress loop example on line 10 / 13
View even-odd.php
<?php
// WP_Query Arguments
$args = array(
'order' => 'DESC',
'posts_per_page' => 5
);
// The Loop
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
$even_odd_class = $wp_query->current_post % 2 == 0 ? 'even' : 'odd';
@dospuntocero
dospuntocero / show page children wordpress
Last active May 31, 2019
show page children wordpress
View show page children wordpress
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
You can’t perform that action at this time.