Skip to content

Instantly share code, notes, and snippets.

@jprieton
jprieton / gist:9809052
Last active August 29, 2015 13:57
Cambio masivo de post_type
UPDATE wp_posts p
LEFT JOIN wp_postmeta pm ON p.ID=pm.post_id
SET
p.post_type='new_post_type',
p.guid=REPLACE(p.guid, 'old_post_type', 'new_post_type')
WHERE
p.post_type='old_post_type'
@jprieton
jprieton / popular_posts.php
Last active August 29, 2015 14:01
Devolver los post mas vistos usando el plugin Wordpress Popular Posts
@jprieton
jprieton / timthumb_htaccess
Last active September 24, 2020 14:06
.htaccess para usar timthumb
# BEGIN TimThumb .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} (?i)(jpg|jpeg|png|gif)$
RewriteCond %{QUERY_STRING} h=([1-9]) [OR]
RewriteCond %{QUERY_STRING} w=([1-9])
RewriteRule (.*) ./path/to/timthumb.php?src=%{REQUEST_URI}&%{QUERY_STRING}
</IfModule>
@jprieton
jprieton / gist:a4e805339abfdce05db1
Created May 13, 2014 17:19
Dar formato a un numero por JavaScript
var number = 10000000.00;
if (window.Intl && typeof window.Intl === "object") {
numberFormatted = new Intl.NumberFormat("es-VE", {minimumFractionDigits: 2}).format(number);
} else {
// fallback if Intl is not supported
numberFormated = number;
}
alert(numberFormatted);
@jprieton
jprieton / jpb_change_user_pass
Last active August 29, 2015 14:01
Cambio de contraseña con verificación de contraseña anterior en WordPress
<?php
function jpb_change_user_pass() {
$old_pass = filter_input(INPUT_POST, 'old_pass');
$new_pass = filter_input(INPUT_POST, 'new_pass');
$new_pass_verify = filter_input(INPUT_POST, 'new_pass_verify');
if (empty($old_pass) or empty($new_pass) or $new_pass != $new_pass_verify or !is_user_logged_in()) {
return;
@jprieton
jprieton / jpb_logout.php
Last active August 29, 2015 14:01
Cierra la sesión del usuario en WordPress y redirige al home
<?php
function custom_logout() {
$logout = (bool) filter_input(INPUT_GET, 'logout');
if ($logout) {
wp_logout();
echo '<script type="text/javascript">window.location = "' . home_url() . '";</script>';
}
}
@jprieton
jprieton / jpb_login.php
Last active August 29, 2015 14:01
Inicio de sesion en WordPress
<?php
function jpb_login() {
$user_login = filter_input(INPUT_POST, 'user_login');
$user_password = filter_input(INPUT_POST, 'user_password');
$remember = (bool) filter_input(INPUT_POST, 'remember');
if (!empty($user_login) && !empty($user_password)) {
$creds = array();
$creds['user_login'] = $user_login;
@jprieton
jprieton / jpb_list_categories.php
Last active August 29, 2015 14:01
Obtener la lista de subcategorias pertenecientes a la misma categoria principal de la subcategoria actual en WordPress
<?php
$term_id = (int) get_query_var('cat');
$current_term = get_term($term_id, 'category');
if ($current_term->parent !== 0) {
$is_parent = FALSE;
while (!$is_parent) {
$current_term = get_term($current_term->parent, 'category');
if ($current_term->parent == 0) {
$is_parent = TRUE;
@jprieton
jprieton / jpb_register_meta_box.php
Last active August 29, 2015 14:01
Crear metadata editable en la pagina contacto
<?php
function jpb_register_meta_box() {
if (!class_exists('RW_Meta_Box') or !is_admin()) {
return;
}
$post_id = $current_post = false;
// verify that this is a product category page
if (is_product_category()){
global $wp_query;
// get the query object
$cat = $wp_query->get_queried_object();
// get the thumbnail id user the term_id
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id );
// print the IMG HTML