Skip to content

Instantly share code, notes, and snippets.

Francisco arenas dospuntocero

View GitHub Profile
@dospuntocero
dospuntocero / gist:78270abab305af589d87a7300ba50443
Created Apr 6, 2019
changing the keyboard configuration on windows 10 - for good. using powershell
View gist:78270abab305af589d87a7300ba50443
if you want to know which keyboards do you have available, use this command
Get-WinUserLanguageList
if you want to add a new one and you know the languagetag and the keyboard layout you want you can use something like this
Set-WinUserLanguageList -LanguageList en-US, en-001 -Force
if you want to remove from the list of posibilities the ones you dont want to use, just do the following (pressing enter after each line):
@dospuntocero
dospuntocero / functions.php
Created Mar 30, 2019
combination of parts needed to add a new parameter on the wordpress url for sorting.
View functions.php
<?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 / repeaterfield.php
Created Mar 27, 2019
solution found on advanced custom fields support forum. kudos to EbbandFlow
View repeaterfield.php
<?php
//For Use with Repeater Field
$videos = get_field('videos');
$videos_raw = get_field('videos', FALSE, FALSE);
//Add the Thubmnail to the $videos object
foreach($videos_raw as $key => $video_raw) :
$videos[$key]['video_thumb'] = get_video_thumbnail_uri($video_raw['field_5449746362c3d']); //Replace 'field_5449746362c3d' with your field's Field key (obtainable by going to screen options in the fields admin, and setting 'Show Field Key' to 'Yes')
endforeach;
@dospuntocero
dospuntocero / youtube-id.php
Created Mar 3, 2019 — forked from leogopal/youtube-id.php
PHP function to get youtube ID from URL
View youtube-id.php
<?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 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'
)
View gist:9f0799c866c48a530f89d9fc9008552a
<?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' );
You can’t perform that action at this time.