add_rewrite_rule with bottom priority doesn’t handle the WordPress pages

When you point a rule to anything other than index.php, it gets interpreted as external and written to the .htaccess file. After external rules are parsed, requests get directed to WordPress, which parses the internal rules in php. This is the internal version: function custom_rewrite() { add_rewrite_rule( ‘^(bar|baz|foo-.*)’, ‘index.php?my_var=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘custom_rewrite’ … Read more

Dynamically Override Fancy Title – Part II

I finally got it. The final version of the function is: <?php // ACCOMODATION TITLE add_filter (‘presscore_get_page_title’,’netbooking_presscore_get_page_title’,10,1); function netbooking_presscore_get_page_title ( $title ) { if( is_page( ‘1057’ ) ){ $GLOBALS[“content”] = $content; // This reads input considering a default value in case of error $INPUT = function($param, $default, $prefix = true){ $key = $prefix ? ‘netbooking_structure_’.$param … Read more

POSTS list in WordPress by views

Seems like you already have the custom field for views set up since that’s a phpMyAdmin screenshot. If so, you can use order_by=”post_views_count” in most wp_query based calls. For instance: $args = array( ‘post_type’ => ‘your_post_type’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘post_views_count’, ); $query = new WP_Query( $args ); //…and on with the loop <?php … Read more

Update some database fields when post is saved

Best way for storing them is WordPress’ Options Mechanism. ANd best way to trigger it when a post saved is using WordPress save_post action. Example : add_action( ‘save_post’, ‘count’ ); //Execute count() when a post saved/updated function count() { your codes here … //save them to DB update_option(“lines-of-code”, $lines); update_option(“disk-space”, $diskspace); … }

submit the form to same page

name is a WordPress query var, by submitting a form with that var set, you are changing the main query. All form elements should always be prefixed with something unique to prevent clashes like this.

Geocoding an Exploded Custom Field Array

This isn’t a complete answer, but a couple of bits of advice – Don’t geocode the addresses on front-end requests, it’s a waste of cycles. An address only needs to be geocoded once, then you can store the lat/lon data with your post meta. Use a save_post hook to do the geocoding when the post … Read more

How to allow PHP In WordPress text widget

Instead you should consider using a shortcode. This is exactly the problem that shortcodes try to solve. By default, Widgets don’t process shortcodes, but that can be easily changed. add_filter( ‘widget_text’, ‘do_shortcode’ ); This would allow you to use any shortcodes in the Widget text area. Next would be to get the PHP code you … Read more

Specific Loop For 2 Within Each

i use this code in my portfolio http://pocketapps.co/ <?php $args = array( //your argument code ); query_posts($args);?> <ul> <?php $ls=0; while ( have_posts() ) : the_post(); ?> <?php if($ls%2==0): echo ‘</li><li>’; endif; ?> <div class=”app”> //your code here </div> <?php $ls++; endwhile; wp_reset_query(); ?> </ul>

Make Selected Mutiselect Items “selected”

I’m assuming your $selected variable contains an array of values for the currently selected items? You can’t use selected in this case (with multi select boxes) because it only compares two strings. It won’t test to see if the value is in an array. Instead, use a ternary statement and in_array() <?php foreach ($cats as … Read more