WordPress Types Plugin output data sets using Get_Posts radio and checkboxes

You can use the WordPress Types Plugin to create custom groups of posts/pages type objects, which include the standard title, body WYSIWYG and featured image (or not), along with any number of any types of fields, checkbox, radio buttons etc. etc. 

Then you can use PHP/ Widgets on pages to output categories of data items

This will output all 

$pid = get_the_ID();
$argsDeals = array( 'post_type' => 'product-data-set', 'post_status' => 'publish','posts_per_page' => 50,
'meta_query' => array( array( 'wpcf-featured-item-list' => 'checkbox2' ,'value'=>'checkbox2' ,'compare' => 'LIKE' )) ,'meta_key' => 'wpcf-homepage-list-order','orderby' => 'meta_value_num','order' => 'ASC' );
$my_hotdeals = get_posts( $argsDeals );
foreach( $my_hotdeals as $post ) :
 echo get_the_title($post->ID);
 echo get_permalink( $post->ID);
 if ( has_post_thumbnail($post->ID) ) {
 echo get_the_post_thumbnail($post->ID,'75square-thumb');
 if (get_post_meta( $post->ID, 'wpcf-custom-text',true) != '') {
  echo get_post_meta($post->ID, 'wpcf-custom-text',true) ;

The text in bold is what you change depending on your custom posts/ fields. – they are in order:

  • Name of custom post type
  • Checkbox group with slug “featured-item-list
  • When the specific check box is ticked, the value is set to “checkbox2”
  • The homepage-list-order field is a numeric field for ordering the output
  • A text field with slug “custom-text”

You can also filter by comparing text fields or radio selectors (selecting a category)

It is the same as above, but instead you change the get post args:

$argsDeals = array( 'post_type' =>'product-data-set', 'post_status' => 'publish','posts_per_page' => 50,
 'meta_query' => array( array( 'wpcf-product-name' => 'yes', 'value' => 'item1', ) ),'meta_key' => 'wpcf-priority','orderby' => 'meta_value_num','order' => 'ASC', 'exclude' => $pid2 );

And the fields are similar except product-name is a radio button option which is matched to “item1” and priority is again a numeric field which orders the output.

To get a list of all checkbox values for a current product/ object – use this code to enter the checkbox values into an array:

$catlist = array();
if (get_post_meta( $post->ID, 'wpcf-featured-products',true) != '') {
 foreach (get_post_meta($post->ID, 'wpcf-featured-products',true) as $key => $value) {
 foreach ($value as $key2 => $value2) {
foreach ($catlist as $key => $value) {
 echo $value . ' ';

This code would be inside the loop which considers and extracts data for one object

  • Checkbox list slug is featured-products
  • Array Featured-product ( Array $Key ( $Value2 = checkbox1 ) ) – loop through the inner array and copy to your own array to extract a list of category names
  • Print all the checkbox values for the current element you are considering

WordPress only show content for logged in admin user

Sometimes one might only want to show some content for logged in admin users, or a specific admin user – for testing purposes etc.

you can use this code:

$current_user = wp_get_current_user();
if($current_user->user_email == "email@address.co")
  function(); // this function will only happen when this one admin user is logged in.
<p>This HTML will only show when the user is logged in</p>

For content to be shown when a user is logged in as an admin in general, this can be used:

<?php if ( is_user_logged_in() ) {
  echo "This will be shown if a user is logged into the admin section.";
} ?> 

Various JavaScript Programming Notes

To make a 2 dimensional array

var v=new Array();
var v2=new Array();
v[0]=1; v[1]=7; v2[0]=v;
var x = v2[0][0] // x is 1;

Add to an array


Function – If string S is in array A, then return true

function inArray(string, array){
 for(var i = 0;i < array.length;i++){
 if (array[i]==string){
 return true;
 return false;



Featured Video rather than Image for WordPress

Some templates have a featured image, but sometimes you want a video instead… But not all the time..

You can set some custom fields, and then add in PHP – if the field has something in it – display the embedded video (at the same size the featured image would have been…)

The text in the custom field should just be the ID code for YouTube or Vimeo (or you can add your own if you want… but you need to add the embed code to the PHP)

The code gets the ID and inserts it into the embed code.

if (post_custom(‘a YouTube ID Code’)) {
echo ‘<iframe width=”640″ height=”402″ src=”http://www.youtube.com/embed/’ . get_post_meta($post->ID, ‘a YouTube ID Code’, $single = true) . ‘” frameborder=”0″ allowfullscreen></iframe>’ ;
else if (post_custom(‘a Vimeo ID Code’)){
echo ‘<iframe src=”http://player.vimeo.com/video/’ . get_post_meta($post->ID, ‘a Vimeo ID Code’, $single = true) . ‘?title=0&amp;byline=0&amp;portrait=0″ width=”400″ height=”225″ frameborder=”0″ webkitAllowFullScreen allowFullScreen></iframe>’ ;


add the YouTube or Vimeo ID code to a custom field:

  • a YouTube ID Code
  • a Vimeo ID Code


  • bH9tJXm2Bcw
  • 31934775

From the original YouTube links:

  • http://www.youtube.com/watch?=bH9tJXm2Bcw&feature=channel_video_title
  • http://vimeo.com/31934775

Add custom fields to posts and pages

Just to quickly add info to a page

enable custom fields with the dropdown

then add this code:

echo get_post_meta(get_the_ID(), ‘your-name-of-custom-field’,  true);

Shift Joomla and WordPress installs

  • Copy HTML/CSS/etc. – folders. everything
  • Move the database

Login to old cPanel -> PHPmyAdmin
select databse, check all tables, “export” – all (custom – all options)

Go into new PHPmyAdmin
import all

edit (WP-config.php,. config.php (in Joomla)

Edit the database location:

  • Databse name (same)
    But – might be something like:
    old DBS name is “shop”
    new name is “rotapixt_shop”
  • Server (local host if it is on the same server, else the address (EG: http://cpanel.something.com)
    it’s possible to install the HTML files on one FTP account server, and install the database on a different server….
  • Database user username:  (hosting account username/ password login)
  • Database user password

In website hosting – you have an account username and password, this is the same for :

  • FTP account
  • cPanel login (maybe PHPmyadmin has a different password)
  • Database / MySQL username / password (would be the same as PHPmyAdmin)

Joomla – Configuration.php:

  • host $host
  • DB name $db
  • username MYSQL $user
  • pass $password

WordPress – wp-config.php

  • commented with labels ~


HTML goes in the htdocs folder

http://localhost/cpanel(then click “PHPMYADMIN” to edit database

  • DBS name = whatever you call it in PHPmyadmin
  • server = localhost
  • username = root
  • password = “” (nothing)

My default WordPress Settings

I always set this stuff up like this:
  • General
    • Site title/tagline
  • Writing
    • Default Post category – change name from default to (something with relevant keywords in it)
      Edit this in Posts->Categories
  • Reading
    • Front page displays “static page”
      • Create 2 new blank pages called  “home” and “blog” – set these two ~
  • Discussion
    • Disable the 2 emailers when people comment
  • Permalinks
    • Custom
      • /%category%/%postname%/

My Favourite WordPress Extensions Plugin Add on

  • Peter’s Post Notes
    Great for adding random notes to posts, pages, of the Admin dashboard section. You can add more, edit them, and yeah – just text.
  • PHP Execution
    ability to add <php something; ?> PHP scripts in the “HTML” section of pages and posts, but there are bugs… maybe I’ll try to find another one – I’ve had problems with this sort of thing before… I’ll keep looking…
  • TinyMCE Advanced
    Advanced text editing options, really useful.
  • Simple Meta Tags – ability to add your own Title, Description, Keywords to each page or defaults.
I’m sure there are lots of amazing things out there – and I love WordPress in general
What do you use? What web tools do you love?

WordPress template editing Adding custom menu, sidebar, layout etc.

You can edit a WordPress template so that it is just a HTML file which inserts the body text, but you can use some powerful tools that make the template easier to edit, and more dynamic.

Custom Menu

You can use a custom menu to make the header links, sidebar links, footer links, or other list of links to pages.

You can add, remove, reorder these links in the WordPress admin section, so no need to sift through code, or edit HTML.

  • Just go to the admin section, click on Appearance -> Menus
  • Click the + to make a new menu
  • add a name
  • in the left hand side, you can choose what pages you want to add
  • then drag the items to reorder them
To print a menu, use:
<?php wp_nav_menu( array('menu' => 'Menu Name' )); ?>
This will print an unordered list of the menu items.
You can display them next to each other, change the colour of the current page, and more fancy things using CSS.

Custom Sidebars

You can add different things to the sidebar using widgets
WP-admin -> Appearance -> widgets
You can add a text widget to add your own HTML
This code can be added to your sidebar.php file to print the widgets

if ( 'content' != $current_layout ) :
<div id="secondary" role="complementary">
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<aside id="archives" class="widget">
<h3 class="widget-title"><?php _e( 'Archives', 'twentyeleven' ); ?></h3>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
<aside id="meta" class="widget">
<h3 class="widget-title"><?php _e( 'Meta', 'twentyeleven' ); ?></h3>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
<?php endif; // end sidebar widget area ?>
</div><!– #secondary .widget-area –>
<?php endif; ?>


Custom site layouts and structures

You can have different structures to your site. one page with no sidebars, one or two sidebars etc.

Just make different “page.php” files for each layout type, and you can set them in the page settings for each page.

just add
Template Name: Snarfer

To your custom template

For more info: See the WordPress page on this topic

Custom CSS and Javascript in your Admin Section of WordPress

If you edit files in the admin folder of WordPress – you will lose all changes when you upgrade to a new WordPress version, so just add this to your functions.php file in your current WordPress theme.

function custom_admin_css() {
echo '
<style type="text/css">
add_action('admin_head', 'custom_admin_css');

Adding a second loop to your WordPress site

You can list blog posts anywhere in your website, by adding a second loop.

Use this code: (edit the category name and number of posts to show – you can also edit what the loop shows, just listing the names of posts, linking to them, or add the summary/content…)

<?php rewind_posts(); ?>

<?php query_posts(‘category_name=NAME&showposts=5′); ?>

<?php while (have_posts()) : the_post(); ?>
<!– Do featured stuff… –>
<li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></li>
<?php // the_excerpt(); ?>
<?php //<div class=”entry”>
// the_content();
//</div> ?></li>
<?php endwhile;

<p class=”right”><a href=”/NAME/”>All posts</a></p>

The last link is just a link to the category name so you can show all.