function adminPaginationLimit(){
global $per_page, $wp_query;
$per_page = 500;
$posts_per_page = 500;
$wp_query->query(‘showposts=’. $posts_per_page);
}
add_action(‘admin_head’, ‘adminPaginationLimit’);
Tag Archives: Posts
WordPress query to fetch posts orders by date added as custom field
<?php
$postQuery = “SELECT distinct(wposts.post_title),cast(wpostmeta.meta_key as DATE),wposts.ID,wposts.post_content,wposts.post_date,wposts.comment_count
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)
LEFT JOIN $wpdb->postmeta AS wpostmeta ON wposts.ID = wpostmeta.post_id
WHERE wpostmeta.meta_key = ‘dvd_release_date’ AND $wpdb->term_taxonomy.taxonomy = ‘category’ AND $wpdb->term_taxonomy.term_id IN(‘3952’)
ORDER BY wpostmeta.meta_value DESC LIMIT $itemPerPage”;
$postResults = $wpdb->get_results($postQuery, OBJECT);
foreach( $postResults as $post ) {
echo $post->post_title;
}
?>
show post which belong to more than 1 given categories – wordpress
<?php query_posts(array(‘category__and’ => array(22,27))); ?>
Print the substring of the post content – WordPress
<?php
$content = get_the_content();
echo substr(strip_tags($content), 0, 100);
?>
Categories of a post – WordPress
<?php
foreach((get_the_category(POST-ID)) as $category) {
echo $category->cat_name;
}
?>
WordPress query to fetch the pages
<?php global $wpdb; $querystr = " SELECT distinct(post_title) ,ID,post_title FROM $wpdb->posts WHERE post_type='page' AND post_status='publish' "; $pageposts = $wpdb->get_results($querystr, OBJECT); ?>
WordPresss query to fetch the posts under the given categories
<?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); ?>
Permalink from post id – Wordpres
<?php echo get_permalink(postId) ; // will return the permalink ?>
Plugin that allows php codes in post/page – WordPress
“Exec-PHP” plugin allows us to add php codes in posts/pages