Skip to content

Instantly share code, notes, and snippets.

View jartes's full-sized avatar
🦖

Joan Artés jartes

🦖
View GitHub Profile
@jartes
jartes / get_first_image.php
Created September 20, 2012 10:17
Get First Image from a WordPress Post
get_thumbnail_image_src() {
/**
* @todo
* * Return or echo
*
*
*/
global $post;
if ( has_post_thumbnail( $post->ID ) ) {
@jartes
jartes / functions.php
Created October 1, 2012 14:32
Hide category from the Home Query
// More info: http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
function hide_cat_home_query ( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$the_cat_id = get_cat_ID('cat_name');
$query->set('cat', '-'.$the_cat_id);
}
}
add_action('pre_get_posts', 'hide_cat_home_query');
@jartes
jartes / tag_to_cat.sql
Created October 2, 2012 10:16
Change category to a tag in WordPress
update wp_term_taxonomy set taxonomy = 'category'
where term_id in (
select a.term_id
from wp_terms a
where a.name in (
'cat_name'
)
)
@jartes
jartes / gist:5090783
Created March 5, 2013 14:48
[WordPress] Obtener el número de padres de una página. Si no tiene, n = 0. Para posts, igual pero cambiando get_page por get_post
function get_page_parent_number( $pagina = null ) {
$n = 0;
while ( $pagina->post_parent != 0 ) {
$pagina = get_page( $pagina->post_parent );
++$n;
}
return $n;
}
@jartes
jartes / redirect.php
Created March 18, 2013 10:48
Redirect WordPress page to URL specified by a custom field with key "url_to_go"
function lets_redirect( $query ) {
if ( !is_admin() ) {
if ( $query->is_page() && $query->is_main_query() ) {
$redirection = get_post_meta( $query->queried_object->ID, 'url_to_go', true );
if ( $redirection != '' ) {
?>
<script language="javascript" type="text/javascript">
window.location.href="<?php echo $redirection ?>";
</script>
<?php
@jartes
jartes / admin-bar.php
Created March 25, 2013 12:28
[WordPress] Remove Admin Bar on front-end
add_filter( 'show_admin_bar', '__return_false' );
remove_action( 'init', 'wp_admin_bar_init' );
@jartes
jartes / cat_loop.php
Last active December 17, 2015 15:19
Get 20 posts from one category by slug
$args = array(
'category_name' => 'slug',
'posts_per_page'=> 20
);
$mis_posts = new WP_Query( $args );
while ( $mis_posts->have_posts() ) {
$mis_posts->the_post();
/**
@jartes
jartes / birthday.php
Created July 10, 2013 12:27
Formulario fecha de nacimiento
<select name="dia" id="dia">
<option value=""></option>
<?php
$i = 1;
while ( $i <= 31 ) {
if ( $i < 10 ) {
$dia = '0' . $i;
}
<?php
/*
UPDATED: December 31, 2011.
Modifications:
- Truncated the longest country names, including:
-- British Indian Ocean Territories (Chagos Archipelago) -> British Indian Ocean Territories
-- South Georgia and the South Sandhich Islands -> South Georgia & S. Sandwich Islands
@jartes
jartes / wpcf7-acceptance
Created March 10, 2014 16:03
Control WPCF7 Acceptance
jQuery('#check-term').bind('change', function() {
if(jQuery(this).is(':checked')){
jQuery("#acepta-condiciones").hide();
}
else {
jQuery("#acepta-condiciones").show();
}
});