Skip to content

Instantly share code, notes, and snippets.

View pedroelsner's full-sized avatar

Pedro R. Elsner Begosso pedroelsner

View GitHub Profile
@pedroelsner
pedroelsner / gist:3161429
Created July 23, 2012 00:07
#2 - WP_query personalizado
<?php
function like_title_posts_where($where, &$wp_query) {
global $wpdb;
if ( $like_title = $wp_query->get('like_title')) {
$where .= ' AND '.$wpdb->posts.'.post_title LIKE \''.esc_sql(like_escape($like_title)).'\'';
}
return $where;
}
@pedroelsner
pedroelsner / gist:3161421
Created July 23, 2012 00:00
#1 - WP_query personalizado
<?php
// Seleciona todos os posts publicados
$query = new WP_query(
array(
'post_type' => 'post',
'post_status' => 'publish'
)
);
<?php
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Conta' => array(
'className' => 'Conta',
'foreignKey' => 'conta_id',
@pedroelsner
pedroelsner / gist:3094973
Created July 12, 2012 01:11
Exemplo: Rafael - FilterResults
<?php
$this->FilterResults->addFilters(
array(
'OR' => array(
'perfil' => array(
'Vaga.perfil' => array(
'select' => $this->FilterResults->select('Perfil', array('1' => 'select 1'))
)
),
'cidade_id' => array(
<?php
try{
$webservice = new novw_webservice();
$result = $webservice->LerCadastro(array('cpf' => '000.000.000-00'));
unset($webservice);
} catch (exception $e) {
wp_redirect(home_url() . '/error?description=' . $e->faultstring);
exit();
}
<?php include(TEMPLATEPATH . '/includes/need_login.php'); ?>
<?php get_header(); ?>
<div class="ym-wrapper wrapper-content">
<div class="ym-wbox">
<h1 class="area-title area-idenfiticacao"><?php echo wp_title(); ?></h1>
@pedroelsner
pedroelsner / gist:3073937
Created July 9, 2012 02:52
#6 - Rewrite WordPress
<?php
function my_template_redirect() {
global $wpdb;
global $wp_query;
global $current_user;
if ($wp_query->get('custom_page') == 'contato') {
// Definimos o título da página
add_filter('wp_title', create_function('$a', 'return "Contato «";'), 100);
@pedroelsner
pedroelsner / gist:3073911
Created July 9, 2012 02:42
#5 - Rewrite WordPress
<?php
function my_query_vars($query_vars) {
$query_vars[] = "custom_page";
return $query_vars;
}
add_filter('query_vars', 'my_query_vars');
@pedroelsner
pedroelsner / gist:3073889
Created July 9, 2012 02:36
#4 - Rewrite WordPress
<?php
function my_rules_array($rules_array) {
global $my_rewrite_rules_array;
return $my_rewrite_rules_array + $rules_array;
}
add_action('rewrite_rules_array', 'my_rules_array');
@pedroelsner
pedroelsner / gist:3073851
Created July 9, 2012 02:17
#3 - Rewrite WordPress
<?php
function load_my_rewrite_rules() {
// Carrega nossa variável
global $my_rewrite_rules_array;
// Carrega as regras do WP
$wp_rules = get_option('rewrite_rules');
/**