Show Only Pings (Pingbacks+Trackbacks) Number on Wordpress - wordpress

Is there a way to display just ping counts (number) on Wordpress?
Actually there are comments_number function but that showing total count of comments, pingbacks and trackbacks.

The following code works on WordPress 2.9.1. It may work on other versions, but I only tested it against 2.9.1.
<?php
global $wpdb;
$post_id = get_the_ID();
$total_ping_count = $wpdb->get_var("SELECT count(comment_id) FROM $wpdb->comments WHERE comment_type = 'pingback'");
$total_approved_pings = $wpdb->get_var("SELECT count(comment_id) FROM $wpdb->comments WHERE comment_type = 'pingback' and comment_approved = 1");
$post_ping_count = $wpdb->get_var("SELECT count(comment_id) FROM $wpdb->comments WHERE comment_type = 'pingback' and comment_approved = 1 and comment_post_id = $post_id");
echo "The total number of pings on this site is $total_ping_count.\n";
echo "The total number of approved pings on this site is $total_approved_pings.\n";
echo "The total number of approved pings on this post is $post_ping_count.\n";
?>
The above code gives counts just for pingbacks. If you want trackbacks instead of pingbacks simply change comment_type = 'pingback' to comment_type = 'trackback' or if you want a combined count change it to comment_type IN ('pingback', 'trackback').

Not exactly sure what you want: only show pingbacks? If so, and I haven't tried it, but Template Tags/wp list comments « WordPress Codex shows listing pingbacks and options.

Related

How to create pagination on wordpress?

Hi all I am a new of wordpress,I want to create pagination next and previous, I have problame with pagination next and previous, I cant find the way to do it.I try to hard to do it, but still can not, How can I do it , Help me please. thanks you.
here is my code page_movie.php
<?php
global $wpdb;
$lastedate = $wpdb->get_var("
SELECT substr(meta_value,1,7) as Date
FROM ".$wpdb->prefix."postmeta
WHERE meta_key = 'details_release_date'
AND meta_value <> ''
AND meta_value >= '".date('Y-m-d')."'
GROUP BY substr(meta_value,1,7)
ORDER BY substr(meta_value,1,7) ASC
LIMIT 1
");
_e(do_shortcode('[movies limit="-1" type="Now Showing"]'));
_e(do_shortcode('[movies limit="-1" type="Coming Soon" compare="BETWEEN" start="'.date('Y-m-d').'" end="'.$lastedate.'-31"]'));
_e(do_shortcode('[movies limit="-1" type="Released" compare="BETWEEN" start="'.date('Y').'-01-01" end="'.date('Y-m-d').'"]'));
?>
<?php the_posts_pagination( $lastedate ); ?>

Delete posts with custom field date older than current date via cronjob

I want to make a cron job witch deletes all posts older than the date in a custom field of the post. I got following function within my functions.php My custom field name is bewerbungs_frist.
function foobar_truncate_posts(){
global $wpdb;
$currenttime = new DateTime();
$currenttime_string = $currenttime->format('Ymd');
# Set your threshold of max posts and post_type name
$post_type = 'job';
# Query post type
$query = "
SELECT ID FROM $wpdb->posts
WHERE post_type = '$post_type'
AND post_status = 'publish'
ORDER BY post_modified DESC
";
$results = $wpdb->get_results($query);
# Check if there are any results
if(count($results)){
foreach($results as $post){
$customfield = get_field('bewerbungs_frist', $post->ID);
$customfield_object = new DateTime($customfield);
$customfield_string = $customfield_object->format('Ymd');
if ( $customfield_string < $currenttime_string ) {
echo "The value of the custom date field is in the past";
echo $customfield_string;
$purge = wp_delete_post($post->ID);
}
}
}
}
foobar_truncate_posts();
I use a plugin to handle my cronjobs. The Hock name is: foobar_truncate_posts and Arguments is []
The cronjob works but it does not delete those post with the date of the customfield older than todays date. The two variables are the same.
$currenttime_string 20130820
$customfield_string 20130820
there's a typo in your code, you're missing an 's' at the end of $result.
This:
foreach($result as $post){
Should be this:
foreach($results as $post){
I just tried it out. Once you make that fix the wp_delete_post() works great.
EDIT
I'm really unclear on what you're trying to do. You want to check if the custom field is set to some time in the past? What purpose does the continue serve? Also, I'm guessing you're using Advanced Custom Fields (ACF). Using the jquery Date Picker, you can format your date to Ymd by default so you don't have to convert it to a DateTime object.
At any rate, this function should explain how to properly set and compare time values, you should be able to take it from there:
function foobar_truncate_posts(){
global $wpdb;
$currenttime = new DateTime();
$currenttime_string = $currenttime->format('Ymd');
# Set your threshold of max posts and post_type name
$post_type = 'post_type_job';
# Query post type
$query = "
SELECT ID FROM $wpdb->posts
WHERE post_type = '$post_type'
AND post_status = 'publish'
ORDER BY post_modified DESC
";
$results = $wpdb->get_results($query);
# Check if there are any results
if(count($results)){
foreach($results as $post){
$customfield = get_field('bewerbungs_frist', $post->ID);
$customfield_object = new DateTime($customfield);
$customfield_string = $customfield_object->format('Ymd');
if ( $customfield_string < $currenttime_string ) {
echo "The value of the custom date field is in the past";
$purge = wp_delete_post($post->ID);
}
}
}
}
foobar_truncate_posts();

Paginate, search & sort WordPress $wpdb query for external table

I have a custom table (ERA_Data) in my WP database, which I'd like to add pagination, column sort & search to.
Currently the following code successfully grabs the data (over 4000 entries) & displays them;
<?php
global $wpdb;
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data;");
echo "<table>";
foreach($ERA_Data as $ERA_Data){
echo "<tr>";
echo "<td>".$ERA_Data->PartNo."</td>";
echo "<td>".$ERA_Data->Make."</td>";
echo "<td>".$ERA_Data->Carline."</td>";
echo "<td>".$ERA_Data->Model."</td>";
echo "<td>".$ERA_Data->Description."</td>";
echo "<td>".$ERA_Data->Start_Year."</td>";
echo "<td>".$ERA_Data->End_Year."</td>";
echo "</tr>";
}
echo "</table>";
?>
Just so you know, this is all new to me - so I'm happy to read up on further info, but if anyone can provide some code examples that may help - I'd be extremely appreciative.
With regards to pagination, I think 50 or 100 items per page would do.
I'd imagine sort order & search will be far more useful in any case.
I would juts work on this line for anything you need:
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data;");
so change it like this for showing only a 100, 50, etc. results
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data LIMIT 100;");
or
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data LIMIT 50;");
and for pagination, this link would help so much What is the best way to paginate results in SQL Server
for sorting, depending on your column, use this syntax
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data ORDER BY ***COLUMN NAME HERE***;");
Let me know if you have any questions!

Show post count in Wordpress

Is it possible to get the exact counter of each post for display in a theme I'm making? So for example if I have 100 posts, the last post will have a number of 100, the one before that: 99, and so on. I can't use the post's ID on this since this is always incremented by 2 (most of the time) making it highly inappropriate as a counter.
Try this, look at the results you will get the idea.
Don't forget the array starts with 0 not 1.
Each array item will contain the post ID. so if Item(key) nr 15 is the same as the current page ID, then the current item is #16(15+1)
<?php
global $wpdb;
$query = "SELECT `ID`
FROM `$wpdb->posts`
WHERE `post_status` = 'publish'
AND `post_type` = 'post'
ORDER BY `post_date` ASC
"
;
$count = $wpdb->get_col($query);
var_dump($count);
moar info: wpdb
Do look at the query if you agree with my order.
You'll have to use a "counter" there, something like this:
$i=1;
while(have_posts):
....
<h2><?php echo $i.' - ';?><?php the_title();?>
...
$i++;
endwhile;

Wordpress wpdb select from multipe tables

I have a three tables for my wordpress plugin.
videos = id, name
playlists = id, name
video_playlist = id, video_id, playlist_id
how do I get multiple results for multiple tables.
ie, I am busy editing a playlist and would like to display all videos in the playlist.
so the ID for the playlist you are viewing is passed and that is referenced against the video_playlist table to obtain all the video IDs.
Now to take it one step further I would like to also display the names for the Videos.
Here is what I currently have.
<?php if(isset($update)) {
$rows = $wpdb->get_results("SELECT * FROM $table_play_vid WHERE playlist_id = $update->id");
foreach($rows as $row){
echo $row->video_id;
}} ?>
Try something like this.
?php if(isset($update)) {
$rows = $wpdb->get_results("SELECT vp.video_id, v.name FROM $table_play_vid vp, videos v WHERE vp.playlist_id = $update->id and vp.video_id=v.id");
foreach($rows as $row){
echo $row->video_id." ".$row->name;
}} ?>
I think it's a common MySQL query.
SELECT thistable.column, thattable.column FROM thistable,thattable WHERE thistable.something = thattable.something

Resources