First you need to choose which post type you want to list and to choose a custom field to filter by you use the "meta_key" key in the array. The key starts with "wpcf-" and afterwards the name of the custom field you want to use. $posts = query_posts( array( 'post_type' => "event", 'posts_per_page' => … Continue reading Order Custom Post Type by custom Field with Types Plugin in WordPress
Category: PHP
How to put inline javascript in the footer of your page with WordPress
You can do this by adding this code to your template file. This will add a hook. Your javascript code will now be placed in the footer of your page (or where the wp_footer() function is called). <?php function footer_script(){ ?> <script> jQuery(document).ready(function(){ //put your js code here }) </script> <?php } add_action('wp_footer', 'footer_script'); ?> … Continue reading How to put inline javascript in the footer of your page with WordPress
Vagrant up errors on install on Mac OS X
Instead of MAMP I use Vagrant to set up my virtualhosts locally. That way you can emulate your webserver's setup. To configure my Vagrant virtual machine I use PuPHPet. You need to have VirtualBox installed for this. After downloading the PuPHPet configuration manifest you need to start up the virtual box. You do this by executing … Continue reading Vagrant up errors on install on Mac OS X
Tabindex problems with Gravity forms in WordPress
Sometimes there are problems with the tabindex when you use the Gravity forms plugin in WordPress. You can fix this by adding this to your theme's functions.php file //############################################################################### // Fix Gravity Form Tabindex Conflicts //############################################################################### add_filter("gform_tabindex", "gform_tabindexer"); function gform_tabindexer() { $starting_index = 1000; // if you need a higher tabindex, update this number return … Continue reading Tabindex problems with Gravity forms in WordPress
Change the amount of tags in tagcloud in WordPress
Add this piece of code to your theme's function.php file. add_filter('widget_tag_cloud_args','set_number_tags'); function set_number_tags($args) { $args = array('number' => 20); return $args; } Set the number of the amount of tags you want to display on your page. Or you can just use the parameters for the wp_tag_cloud function. <?php $args = array( 'smallest' => 8, 'largest' … Continue reading Change the amount of tags in tagcloud in WordPress
How to make a custom protected page in WordPress
The default password form uses this message: "This post is password protected. To view it please enter your password below:". You can use a custom text to display on a protected page by using a filter in WordPress. Add this code to your theme's functions.php file: <?php function custom_password_form() { global $post; $label = 'protected-page-'.( … Continue reading How to make a custom protected page in WordPress
Get the depth of the current page in WordPress
If you want to get the level of the current page in WordPress you can use this // gets the depth of the current page global $wp_query; $object = $wp_query->get_queried_object(); $parent_id = $object->post_parent; $depth = 0; while ($parent_id > 0) { $page = get_page($parent_id); $parent_id = $page->post_parent; $depth++; } echo $depth; This function will echo … Continue reading Get the depth of the current page in WordPress
How to enable the WordPress maintenance mode
WordPress has a built-in maintenance feature. By adding a ".maintenance" file to your website's root directory with the piece of code WordPress will trigger its maintenance mode. <?php $upgrading = time(); ?> This file is also used during the auto-update process. By using the maintenance mode, users will not see any error messages while you're … Continue reading How to enable the WordPress maintenance mode
Limit the number of post revisions in WordPress
For each saved edit made to a post or a page, WordPress saves a revision in the database. This can really increase the size of your database when your working with a lot of posts or pages. WordPress has a built-in revisions option which you can set in the wp-config.php file. You can also disable … Continue reading Limit the number of post revisions in WordPress
Remove SEO title, keywords, description columns from the post and pages list when using the all-in-one-seo-pack WordPress plugin
I always use the all-in-one-seo-pack for WordPress websites which is a great plugin for SEO purposes. The only drawback is that it screws up the list of pages or posts in your WordPress admin section by adding three extra colums to it (SEO title, SEO keywords, SEO description). To remove these colums go to the … Continue reading Remove SEO title, keywords, description columns from the post and pages list when using the all-in-one-seo-pack WordPress plugin