Tag Archives: Posts

WordPress Plugin Posts – PHPCodezPosts

It can be used to list posts and the output can be managed from admin side

== Description ==

PHPCodez Posts lists posts . The output can be managed from the back end

Advatages
======
1) We can restrict the number posts
1) We can list post randomly
2) We can sort posts by its name,comment count or id
3) We can show comment count with posts
5) We can list post under the selected categories
6) We can exclude posts

== Installation ==

1. Upload the plugin folder to your /wp-content/plugins/ folder.

2. Go to the **Plugins** page and activate the plugin.

3. Go to appearance->widget area and drag the widget “PHPCodez Posts” to the widget area to have this on the sidebar .

Click here to download the plugin

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;
}
?>

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);
?>