Using the Custom Fields in WordPress to Save Time!
Over the past weekend, I spent some time helping a few others on the use of phpbay and phpZon for setting up comparison engines their new sites. Since I come from a database driven website background, I am always trying to shorten the number of times I have to type the same thing over and over, and I often use the WordPress Custom Fields to help accomplish this!
What are WordPress Custom Fields?

If you visit the WordPress page on Custom fields, you will learn a bit more… but in a nutshell, an easy way to understand is that a custom field is used to call a predefined function. For example, in your posts or pages, you could go into the template file (page.php or single.php) and put a small bit of php in place, to handle things you want to show on some posts, I am going to simplify this for this post:
< php if ‘namedcustomfieldkey’ is not blank then ‘dowhatthevaluesays’ or else ‘do nothing’>
Remember last week I mentioned that code is a series of “if – then – else” type statements? In this case, we are asking the page… IF our custom field name exists and IS NOT blank, THEN show something! In the code on your php page, you define what to show for that specific key and value.
Why Use Custom Fields?
Pretty simple… they save time! Even if you only save 2-3 minutes per post, you can see how it will add up over the course of days, weeks etc. For example, on one of my new sites, I have a series of banners I use on pages when no auctions exist. In effect, I write the post, add a custom field for ebay auctions (explained further below) and preview it. Since some manufacturers do not allow resale of their stuff on places like eBay, I join their affiliate programs and use their own banners instead!
For Example, on a post with no results, I may have to type this into the text editor to show a banner for this manufacturer:
< a href=http: / /www. domainname . com/index.php ?option=com_virtuemart&aff_id=6><img src=http: // www. domainname .com/administrator/components/com_virtuemart/banners/dont_get_stuck_sand_468x60.jpg>< /a >
As you can imagine, that can be hard to remember for each post I may need it on! Instead, I place this code inside of the single.php, wrapped inside an if > then statement, and call it with the custom fields! In this case, I ONLY need to write the code one time, and use it over and over again! Additionally, if one of my programs changes, I simply update the code in one spot, versus every post that uses it.
For Example, I can define the meaning of “blackmagic” to be the value of the banner code above, and within my post, instead of typing all of that, I simply put:

Now, I simply tell the php to look for the affbanner KEY, and if it exists on the post, get the VALUE of it to display.
Short Video Using the Custom Fields: Length 3:05
Short Example of the php Code
The image below is a quick and short example of the code I used for the phpbay listings and custom field. There may be some extra characters in it as I try to break the code into each individual function, which makes it easier to troubleshoot. In other words… there are other ways to code this as well.

I will provide some more samples of using the custom fields throughout the next week or two… they are true timesavers!
Do you have shortcuts for getting things done in WordPress? If so, please share…
Previously Published Articles You May Like to Read:
- Update about Custom eBay Banners
- Save on Gas – Supplement your Income with a Profitable Niche Market
- Build a Niche Store WordPress Plugin Review – WPBans







Custom fields are definitely the power of WordPress beyond what you get out of the box.
In conjunction with PHPBay, they become very useful.
It’s a shame that some “offline” editors like ScribeFire don’t offer the option to use them though.
:(
I agree – I have been using them for quite a while on different projects. Once you grasp the power of them, you don’t want to go back to the text editor!
I have another site using CarP to pull in headlines… and it works the same way on the post level.
The possibilities are actually quite endless… and even though most dont realize it, many plugins use the custom fields as well.
Mark
I looked at custom fields some time ago but just wasn’t getting my head wrapped around it so I usually end up going back to posts and making changes manually.
I think I am going to need more on this before it sinks in enough for me to give it a try. I will go through it again later today, maybe I just haven’t had enough Java yet. :)
Thanks Mark, Great Post!! I had no idea it was even there.
I only have so much time in a day to work on IM that I tend to get to the task at hand and don’t take the time to look around and see all the potential of a program like WordPress.
Thanks again!
Bob
Hey thats some great information – I’v never thought about using wordpress custom fields before, didn’t even realise they existing before reading your post! lol
I’ll have to investigate this further obviously – thanks!
Mark,
I think you have an idea of how glad I am you are going over this!
Will you be sharing with us how we know what to put in the “if-then-else” coding? I’ve seen instructions in some plugins that I think have to do with custom fields, but I suspect the authors of these plugins assume readers know more than we may actually know. They throw a few sentences at us that will help those with coding degrees, but not the casual WP users.
Just this past weekend I visited the WordPress help page for custom fields (the one you linked to above), but it is very general, and didn’t help me at all.
So, thank you for taking the time to help educate your readers on this. I’m sold on the value of custom fields. Now, I just need to understand how to create them for my various plugins.
Rochelle
I’m looking forward to more help from you on this topic. Thanks for posting.
Julie
Mark,
This looks like something that could really help especially if you’ve got responsive subscribers or readers.
Anything that saves time and drudgery from the posting process is a welcome change.
Jeff
Mark,
This is about templates.
I am looking to use wordpress to sell ebay products whether BANS software or PhpBayPro or something else doesn’t matter.
I see so many templates and combinations under Templates tab of this site: confused to what to use.
which template: flex theme Vs new bans-wordpress vs phpbay pro
don’t want to restricted by only one theme. Then all sites on web look alike and G may slap them LOL.
I want to be able to select any theme I want and make it integrate with bans. How to do that?
if the domain is deindexed as G did with BANS stores, the wp blog or store or both get deinxed if we build with wp-bans theme.
what is the best way to protect ourselves from such deindexing?
@ Rochelle & Julie –
I hope to find a way to put it into simple enough terms that anyone can not only read it, but understand how it works a bit better.
Getting into the php side can be tricky, especially since I have always been an .asp vbscript guy, and its a bit different!! :-)
@ Roger -
The BEST thing for you to do is find a theme that works for your site and visitors first, then make the adaptations for the monetization model.
The most flexible theme I have used is my BANS-WordPress theme. You can see the same theme here and here, with 2 completely different looks!
plan your SITE for the visitors first… get your own theme in place, then worry about how to get the monetization model in place.
Mark
Mark,
I have the site as an Add on Domain.
I am trying to setup CaRP on the root of this site….and its giving me lot of trouble… :-(
Am getting error..which am not able to understand….its asking me to enter proxy server info(including username/pwd)
I was able to install it on my local machine…
Is it any diff installing CaRP on main root Vs installing on an Add on Domain??
Thanks
@ Madhu –
You only need one instance of CarP installed on the server. There should be no need to even install it for a add-on domain (I could be wrong, but dont think so)
In your CarP config file, just use the same root setup script you use on the primary domain.
I install it inside the /main/ folder, versus public_html… and access it from all domains.
Mark
Hi Mark,
Thank you so much.
Per your instructions, I moved the “carp” to /home/mahost
and tried to run the setup using my primary domain i.e., http://www.myprimarydomain/carpsetup.php
Am getting the error message : Warning: fsockopen() [function.fsockopen]: unable to connect to 216.194.115.244:80 (Connection timed out) in /home/mahost/carp/carpsetupinc.php on line 676
Any thoughts?
Thanks again !
Madhu
@ Madhu –
Since it was already setup once, you may need to check into your carp_config.php file to see if it is already written and being read incorrectly.
M
Mark,
Thanks for your time.
Its setup now…. got the script generated……need to work on getting the feed onto the page.
Madhu
Mark
Can you add the script to this where the phpZon plugin works with the phpBay code to?
I have the post-listings.php file you made with the Arthemia theme and it works great. I’d like to have it where Amazon listings show on top of eBay listings.
Thanks
@Brad – Hey Brad –
I actually have your email marked for reply in my reader, just havent had the time to post it anywhere yet.
The actual code is:
< ?php if( get_post_meta($post->ID, "amazonkey", true)): ?>
< ?php $amkeyword = get_post_meta($post->ID, "amazonkey", true) ?>
Deals on Amazon
$textzon .= '[phpzon]' . $amkeyword . ', "4", "SportingGoods"[/phpzon]';
echo phpzon($textzon);
?>
< ?php else: ?>
< ?php endif; ?>
I don’t know if this will post to the comment or not – if not, I will push it to the post.
You can see I have used the amazon search keyword as the post meta field “amazonkey”. If you already have an eBay keyword in place with a different custom ID, you can just change it to reflect the ebay custom field name, and it will use the same for both.
If your page titles are exact, like, “Levis Jeans”, you can actually dismiss all custom ID fields, and just call your page title to the keywords, by changing the second line to:
< ?php $amkeyword = get_the_title(); ?>
Mark
I tried copying and pasting this code above the eBay key code in the post-listings.php file you provide with Arthemia and nothing shows besides the “Deals On Amazon” title and my sidebar goes bye bye.
I then tried pasting it below the eBay code key and the eBay listings showed but nothing for Amazon and the sidebar still did not show up.
Can you have both Amazon and eBay listings show at the same time with Amazon on top of the eBay listings?
I know I’m doing something wrong because in the video you made it shows exactly what I want.
@Brad – It looks like the paste format has spaced a few of the < & ?php sections, which may be jacking your display.
You need to remove the spaces at the beginning of every line that includes a < ?php. It should be
Starting with the first line:
1: The code looks for the custom field "amazonkey". If it is there and has ANYTHING in it, the rest of the code displays.
If you don't want to go through every post and set a new amazonkey keyword, just change "amazonkey" in line 1 to the value of the ebaykey you are using.
2: Sets the Amazon keyword to search for, to the value of the custom field.
If you want to use the same as eBay, just change "amazonkey" to your ebaykey value, or any wordpress function you want to use for the value. (I outlined using the title, above. But you can use tags, category name, whatever)
3: There should be or tags (remove space between) around the “Deals on Amazon” portion. It looks like the code paste cut them out.
4: Remove the space at the beginning. This line calls the function from the plugin.
5 & 6: I have broken the function into individual blocks to allow for debugging, thus the extra < ?php tags at the end. You could always remove ALL but the first and last tags, and set this entire thing as on code block.
Mark
This is exactly how I have it in the post-listings file. The eBay listings show but no Amazon and the sidebar is still gone. Any ideas? No rush.
ID, “ebaykeys”, true)): ?>
ID, “ebaykeys”, true) ?>
ID, "amazonkey", true)): ?>
ID, "amazonkey", true) ?>
Deals on Amazon
Are You Too Set In Your Ways?
Site Categories
Monthly Archive
My Favorite Places
Blogging Sites
Blogroll
Places I Write
Technology Sites
Site Credits
Niche Store Builder is powered by WordPress, using a modified theme originally inspired by Arthemia.
Home | About | Terms & Privacy