Show only posts with certain custom field in WordPress

Today I spent a few hours on trying to figure how the hell should I display only posts with certain custom field. For those who don’t know, a custom field allows you to add some extra information in each post. That information allows you to do various stuff like displaying a custom image on each post and so on. For example, the thing I tried to do today was to make a gender selector for the current project.

The usual way for displaying posts in WordPress is this:

if (have_posts()) :
 while (have_posts()) : the_post();

What I did is this:

$gender = htmlentities($_GET['gender'], ENT_QUOTES, 'UTF-8');
switch($gender ){
	case "f":
		query_posts('meta_key=gender&meta_value=f');
	break;

	case "m":
		query_posts('meta_key=gender&meta_value=m);
	break;
	default :

	break;
}

After that i continued with regular code:

if (have_posts()) :
 while (have_posts()) : the_post();

That’s all!

Of course, i could use an unlisted tag or category, but i also made a neat custom field manager in the “post.php” page that makes administration of those custom fields a breeze.

WP-Print – show me the link ONLY!

I had to use a WP-Print for a recent WordPress project and, because the way i work, i started to search for plugins AFTER the psd was converted into html and a big part of code was already up & running. So, i downloaded latest version of WP-Print and I tried to use a basic setup:


The problem is that the plugin display the whole link tag (a href="...") and I only needed the href value. I edited wp-print.php (which is inside of you wp-content/plugins/wp-print folder) and i looked for print_link() function.

I saw the function accept three parameters: with first two you can set some extra text and the third (which is boolean) is for setting the way how function behave. So, you can call the function like the previous example or like this:



For showing the way you want. But, because i wanted only the link to that page, i edited wp-print.php and i changed the return of the function when the last parameter was boolean:

if($echo) {
	echo $output."\n";
} else {
	return $output;
}

Became:

if($echo) {
	echo $output."\n";
} else {
	return $print_link;
}

So now, i can use it like this:

  • PRINT !
  • Easy, isn’t it? :)

    Ntz Antispam WordPress Plugin

    Wassup guys?

    I’ve worked a LOT lately and i didn’t have time to do too much things. I know i had promised you some free WordPress themes, but right now I really don’t know when i will launch them.

    Anyhow, few months ago i posted a very effective spam trick. Because that method was somehow hard to apply and everytime you update wordpress or change your theme you had to redo some steps, i though is better to make a plugin for this.

    Is a small plugin, is free to use and redistribute (even i ask you to do so!).

    How to use?

    1. Extract in your wp-content/plugins folder
    2. Activate from your admin area
    3. Watch your spam queue. ZERO. Nothing, NADA!

    How effective is this ?

    I use this trick for over six months. Before I use this, i had around 50 spams/day catched by Akismet. After i put this, i have MAXIMUM five spams/week. Very impressive, isn’t it?

    Dowload from here:

    [download id="1"]

    You don’t have to pay a dime. Anyhow, any link love is well appreciated :D

    Update:

    I also can be found HERE.

    WordPress 2.7 final to be released

    If you use wordpress, you may be happy. The 2.7 will go final in two days from now. The good news is this: old browsers are not supported anymore. Yes, IE6 is included in “old browser” category!

    I already update this blog to 2.7 RC because i just messed up feed.

    What i did? Well.. In my “have more money than Bill Gates” race, i wanted to put some ads in RSS feeds. I set up this in adsense account but… The problem is that i screw things up :( Ads are displayed, but in reader you can see a small excerpt. I spend over two hours to find a fix (including removing the ads!) but with no luck. So… If you know how to fix and you want to help me, be my guest!