<?php global $wpdb; $const="4,8,7"; //category Ids $querystr = "SELECT distinct(wposts.post_title),wposts.ID FROM $wpdb->posts wposts LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN($const) ORDER BY rand() "; $pageposts = $wpdb->get_results($querystr, OBJECT); ?>
Tag Archives: PHP
Find out the IP address – PHP
<?php echo $_SERVER['REMOTE_ADDR'] ?>
Find out the previous page – PHP
<?php echo $_SERVER['HTTP_REFERER'] //will return the previous page ?>
How to find out the difference between two given dates – PHP
<?php $startDate=explode("-", "02-08-2010"); $endDate=explode("-", "26-04-2007"); echo gregoriantojd($startDate[1], $startDate[0], $startDate[2]) - gregoriantojd($endDate[1], $endDate[0], $endDate[2]); //1194 ?>
How to disable error reporting in php?
<?php error_reporting(0);// Will not report any error error_reporting(-1);// Shows all errors ?>
Limits the maximum execution time – PHP
<?php set_time_limit(2); // // If the value is "0" , it will rum for unknown time ?>
How to filter the page title – WordPress
<?php add_filter( 'wp_title', 'filter_wp_title', 10, 2 ); function filter_wp_title( $title, $separator ){ $title ="New Title"; } ?>
Template Redirection – WordPress
add_action('template_redirect','theme_function'); function theme_function(){ if(isset($_GET['sports']) { include(TEMPLATEPATH."/sports.php"); exit(); }}
Category url from its ID – WordPress
<?php echo get_category_link(categoryID); //Category URL ?>
Permalink from post id – Wordpres
<?php echo get_permalink(postId) ; // will return the permalink ?>