Alvaro Neto

This user hasn't shared any biographical information

How To Display Custom Help Box On WordPress Wp-Admin

Have you ever thought about displaying custom messages or help tips for site users on wp-admin?
Add this simple code to your theme functions.php file and a custom help box will be displayed on wp-admin.

add_action('wp_dashboard_setup', 'custom_dashb_add');
function custom_dashb_add() {
	global $wp_meta_boxes;
	wp_add_dashboard_widget('custom_help', 'Help!', 'custom_dashb');
function custom_dashb() {
	echo "<div>
			<ul style='list-style:disc;margin-left:25px;margin-right:10px;padding-top:10px'>
        		<li>Text item for tour custom help</li>

Leave a comment

The New WP e-Commerce List Products and Images Hack

This post was moved to

Well, this code bellow is what I call a “Chewbacca” code, but it works.

I present you the new hack to list products data and images where you want on your theme, if you are working with WP-ecommerce on WordPress.

It was tested on 3.8.5 version, and worked like a charm. If you are using older versions, check the old hack.

Also check WP e-Commerce Product Showroom 2.0.0 on the plugin menu.

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME) or die ("Could not select database, check you wp-config file" . mysql_error());
// if you are note sure about the value of $wp_table_prefix, perform a search for this
// text on your site, the usual value is "wp_" or something
$sql = "select pt.ID, pt.post_title from wp_posts As pt  ";
$sql .= "LEFT JOIN wp_postmeta As mt ON pt.ID=mt.post_id  ";
$sql .= "WHERE pt.post_type = 'wpsc-product' ";
$sql .= "AND pt.post_status = 'publish' ";
$sql .= "GROUP BY mt.post_id ";
$sql .= "ORDER BY pt.post_title ";
$sql .= "LIMIT 3 ";
$qry = mysql_query($sql);
$nrt = mysql_num_rows($qry);
while($rs = mysql_fetch_array($qry)):
$sqlp = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqlp .= "where wm.meta_key='_wpsc_price' and wm.post_id=".$rs[0];
$sqlp .= " GROUP BY wm.post_id";
$qryp = mysql_query($sqlp);
while($rsp = mysql_fetch_array($qryp)):
	$prc = $rsp[0];
$sqli = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqli .= "where wm.meta_key='_thumbnail_id' and wm.post_id=".$rs[0];
$sqli .= " GROUP BY wm.post_id";
$qryi = mysql_query($sqli);
while($rsi = mysql_fetch_array($qryi)):
	$sqlt = "select guid from wp_posts where ID=".$rsi[0];
	$qryt = mysql_query($sqlt);
	while($rst = mysql_fetch_array($qryt)):
		$pht = $rst[0];

$htmlcod .= "<div class='showrpdiv'>\n";
$htmlcod .= "<ul>\n";
$htmlcod .= "<li><a href=".wpsc_product_url($rs[0]).">".$rs[1]."</a><br>";
$htmlcod .= "<a href='".wpsc_product_url($rs[0])."'>";
$htmlcod .= "<img src='".$pht."' style='width:".$tbwid."px'></a>\n";
$htmlcod .= "</li>\n";
$htmlcod .= "<li>".$prc."</li>\n";                   
$htmlcod .= "</ul>\n";
$htmlcod .= "</div>\n";


echo $htmlcod;


WordPress Wp-Admin Menu Hack – Hide Menus From Specific User

Hi there,

If you want to hide menus from a specific user on wp-admin, you can use this hack.

I’ve used the example bellow combined with Role Manager Plugin to hide all the wp-admin menus, displaying just “Comments” for the user.

$user_id = get_current_user_id();
//echo "user:".$user_id;
if ($user_id == 2) {
	function remove_menus () {
	global $menu;
			$restricted = array(__('Dashboard'), __('Agenda'), __('Downloads'), __('Galerias'), __('Depoimentos'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'),  __('Plugins'));
			end ($menu);
			while (prev($menu)){
				$value = explode(' ',$menu[key($menu)][0]);
				if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
	add_action('admin_menu', 'remove_menus');

Just put this code on functions.php.

Leave a comment

Quick solution to display a menu like list of WordPress Custom Post Type Posts(with Custom Taxonomy) in case of emergency

Well, I was in a hurry, the customer needed to have his site working as soon as possible, and I had to display a menu like list of WordPress Custom Post Types working for three different languages, but I didn’t have time to think of a elegant way to make it work. So I’ve created this little hack, that checks the custom taxonomy for each post and uses a conditional to decide what happens as a quick solution, and I’m sharing with you, to use in a case of emergency 🙂
Bem, eu estava com pressa, o cliente precisava ter seu dite funcionando o mais rĂĄpido possĂ­vel, e eu tinha que exibir uma lista tipo menu de Tipos de Posts Customizados WordPress funcionando para trĂȘs diferentes idiomas, mas eu nĂŁo tinha tempo para pensar em um jeito elegante de fazer funcionar. EntĂŁo criei este pequeno hack que verifica a taxonomia customizada para cada post e decide o que acontece usando uma condicional como uma solução rĂĄpida, e estou compartilhando com vocĂȘs, para usarem em caso de emergĂȘncia 🙂

<ul class="submenu">
   // here it's the query for my custom post type - Movies 
   $querycp = array( 'post_type'=>'Movies','posts_per_page' => -1 );
   while (have_posts()) : the_post();
   // here we check what's the post custom taxonomy, if it is the language we need
   $terms = get_the_terms(get_the_ID(), 'movies_cat');
    foreach ( $terms as $term ) {
        $catref = $term->slug;
      <li><a href="<?=get_permalink()?>" title=""><?=get_the_title()?></a></li>



How to reset queries on WordPress

Sometimes you may want to reset WordPress queries, when you are working on a page that displays data from posts of different categories mixed with custom post types, for example(two or more queries on the same page).
Às vezes, talvez vocĂȘ queira resetar suas queries WordPress, quando vocĂȘ estĂĄ trabalhando em uma pĂĄgina que exibe informaçÔes de posts de diferentes categorias misturados Ă  tipos de posts customizados, por exemplo(duas ou mais queries na mesma pĂĄgina).

In this case, all you have todo is use wp_reset_query(); after each loop.
Neste caso, tudo que vocĂȘ deve fazer Ă© usar wp_reset_query(); depois de cada loop.

If you have any doubt, just check the Codex.
Se vocĂȘ tiver alguma dĂșvida, verifique Codex.


Leave a comment

How to Stop WordPress Editor From Removing Break Tags <p> and <br />

If you are experiencing problems with the <p> and <br /> tags on your WordPress site, if they are automatically being removed from your posts causing spacing issues, there’s a simple workaround to deal with it.
Se vocĂȘ estĂĄ enfrentando problemas com as tags <p> and <br /> no seu site WordPress, se elas estĂŁo sendo removidas automaticamente de seus posts causando dificuldades no espaçamento, hĂĄ um jeito simples de lidar com isso.

Download and install the WordPress Plugin TinyMCE Advanced. After that, go to Settings / TinyMCE Advanced / Advanced and check / click the options marked on the picture bellow. WordPress will not ignore anymore the break tags <p> and <br />.
Baixe e instale o Plugin WordPress TinyMCE Advanced. Depois disso, vå até ConfiguraçÔes / TinyMCE Advanced / Advanced e marque / clique as opçÔes assinaladas na figura abaixo. O WordPress não vai mais ignorar as tags de quebra <p> and <br />.

Hope you find this tip useful 😉
Espero que vocĂȘ ache esta dica Ăștil 😉


Leave a comment

WordPress Custom Taxonomy Page Example with Taxonomy Selection Function(select field)

Today I’ll show something quite useful. With just four steps, we will build a custom taxonomy page, that uses a function to build a select field(<select>), that reloads the custom taxonomy page retrieving posts based on the selected option(the selected taxonomy for a specific custom post type).
Hoje vou mostrar algo bastante Ăștil. Com apenas quatro passos, vamos construir uma pĂĄgina de taxonomia customizada, que usa uma função para construir um campo select(<select>), que recarrega a pĂĄgina recuperando posts baseados na opção selecionada(a taxonomia selecionada para um tipo de post customizado).

Step One:

First of all, we need to register a custom post type called video and a custom taxonomy called genre, as I show on my previous post.
Antes de mais nada, precisamos registrar um tipo de post customizado chamado video e uma taxonomia customizada chamada genre, como mostro em meu post anterior.

Step Two:

The function bellow builds a <select> field with options based on taxonomies registered for a specific custom post type. The code also brings a javascript function that redirects to the taxonomy page(taxonomy-genre.php on this example), where you can show the posts from a specific custom taxonomy. Put it on your functions.php file, on your theme directory.
A função abaixo constrĂłi um campo <select> com opçÔes baseadas em taxonomias registradas para um tipo de post customizado especĂ­fico. O cĂłdigo tambĂ©m trĂĄs uma função javascript que redireciona Ă  pĂĄgina da taxonomia(taxonomy-genre.php neste exemplo), onde vocĂȘ pode mostrar os posts de uma taxonomia customizada especĂ­fica. Coloque ele no seu arquivo functions.php, no diretĂłrio de seu tema.

function wp_selcstch_taxonomies( $args = '' ) {
	$defaults = array(			
		'taxonomy' 	=> 'category',		
  		'seltitle'	=> '',
		'selnamen'	=> '',
		'selidcss'	=> '' ,
		'baselink'	=> '', 
		'echo' => 1,
		'hide_empty'   => 0

	$r = wp_parse_args( $args, $defaults );
	extract( $r );

	if ( !taxonomy_exists($taxonomy) )
		return false;
	if( isset( $r['seltitle']) && $r['seltitle']!=""):$idtlt =  $r['seltitle'];else:$idtlt =  '';endif;		
	if( isset( $r['selnamen']) && $r['selnamen']!=""):$idnam =  " name='".$r['selnamen']."' ";else:$idnam = '';endif;
	if( isset( $r['selidcss']) && $r['selidcss']!=""):$idcss =  " id='".$r['selidcss']."' ";else:$idcss = '';endif;	

	$categories = get_categories( $r );
	$swlink = false;
	$swchan = '';
	$output = '';

	// javascript function to redirect(reload) the page
	if( isset( $r['baselink']) && $r['baselink']!=""):
		$output .= '<script language="javascript">';
		$output .= 'function fgotxm(obj){';
		$output .= 'if(obj.options[obj.options.selectedIndex].value!=""){';
		$output .= 'window.location.href=obj.options[obj.options.selectedIndex].value;';
		$output .= '}';
		$output .= '}';
		$output .= '</script>';
		$swlink = true;
		$swchan = " onchange='fgotxm(this)'";

	// html begin
	$output .= "<select".$idnam.$idcss.$swchan.">";
	$output .= "<option value=''>".$idtlt."</option>";;	
	foreach ($categories as $cat):
			if($swlink):$golnk =  " value='".$r['baselink']."/".$cat->slug."' ";else:$golnk = '';endif;
			$output .= "<option".$golnk.">".$cat->name."</option>";
	$output .= "</select>";
	if ( $echo )
		echo $output;
		return $output;

Step Three:

Now, let’s build a taxonomy page, called taxonomy-genre.php and save it on the theme directory.
Agora vamos construir uma pĂĄgina de taxonomia, chamada taxonomy-genre.php e salvĂĄ-la no diretĂłrio de seu tema.

// Let's get the term that was called by the url
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

// here we will pass some parameters for our function that builds the select
$taxonomy   = 'genre'; // the taxonomy slug
$seltitle	= 'Select a Option'; // the select title
$selnamen	= 'select_opt'; // the select name
$selidcss	= ''; // a css id for the select, if wanted
$baselink	= get_bloginfo('url') . "/".'genre'; // and our page base link
// the baselink is the workaround we use to make WordPress find the taxonomy page

$args = array(
  'taxonomy'     => $taxonomy ,
  'seltitle'	 => $seltitle ,
  'selnamen'	 => $selnamen ,
  'selidcss'	 => $selidcss,
  'baselink'	 => $baselink,
  'echo'	 => 0

// here we call the function that builds the select
$combotax = wp_selcstch_taxonomies( $args) ;

// and here we set two conditions based on the term asked on the url to build the query
// first we call all the genres(genre taxonomy) for the video custom post type 
// it will be used when the user calls http://yourdomain/genre/all/ on your browser 
	$querycp = array( 'post_type'=>'video','posts_per_page' => -1 );
// then we call a specific genre(genre taxonomy) for the video custom post type e.g. scifi 
// it will be used when the user calls http://yourdomain/genre/scifi/ on your browser 
	$querycp = array( 'post_type'=>'video', 'genre' => $term->slug, 'posts_per_page' => -1 );	

<?=$combotax."<br>"; // let's display the combo ?>

// and build the loop
if (have_posts()) :
  while (have_posts()) : the_post();								  
    echo get_the_title()."<br>";
    echo get_the_content()."<br>";

Step Four:

Now you must go to wp-admin. On Videos menu, choose Genres and create a main genre called “all”, with slug “all”. Then you can add some child genres, something like “drama” with slug “drama”, “scifi” with slug “scifi”, etc(take a look on the picture).

Genres for videos

Click to open - genres for custom post type video

Agora vocĂȘ deve ir atĂ© o wp-admin. No menu Videos, escolha Genres e crie um genĂȘro principal chamado “all”, com slug “all”. EntĂŁo vocĂȘ pode adicionar alguns genĂȘros filhos, algo como “drama” com slug “drama”, “scifi” com slug “scifi”, etc(dĂȘ uma olhada na figura).

Don’t forget to add some posts to each child genre to display on your custom taxonomy page. Last but not least, a important tip: after registering a custom taxonomy, go to wp-admin and simply visit the permalinks settings page. It flushes all WordPress permalink rules, so it will make your changes related to the taxonomy page work.
NĂŁo esqueça de adicionar alguns post para cada genĂȘro filho para mostrar em sua pĂĄgina de taxonomia customizada. Por Ășltimo, mas importante, uma dica: depois de registrar uma taxonomia customizada, vĂĄ atĂ© o wp-admin e simplesmente visite a pĂĄgina de configuraçÔes de permalinks. Isso faz com que suas regras de permalink sejam zeradas, fazendo suas mudanças relacionadas Ă  pĂĄgina de taxonomia funcionar.

Hope you find this example useful.
Espero que vocĂȘ ache este exemplo Ăștil.


Leave a comment

%d bloggers like this: