$wpdb->flush();
$request = 'SELECT posts.ID AS ID, posts.post_title AS post_title, posts.post_content AS post_content
FROM '.$wpdb->posts.' posts
LEFT JOIN '.$wpdb->term_relationships.' relationships ON relationships.object_id = posts.ID
LEFT JOIN '.$wpdb->term_taxonomy.' taxonomy ON taxonomy.term_taxonomy_id = relationships.term_taxonomy_id
LEFT JOIN '.$wpdb->terms.' terms ON terms.term_id = taxonomy.term_id
WHERE terms.name = "'.$pageTerm.'"
AND posts.post_type = "reference"
AND posts.post_status = "publish"
ORDER BY posts.post_date DESC
LIMIT 0, 2;';
$references = $wpdb->get_results($request);
The request generated is :
SELECT posts.ID AS myID, posts.post_title AS myPost_title, posts.post_content AS myPost_content FROM wp1_posts posts LEFT JOIN wp1_term_relationships relationships ON relationships.object_id = posts.ID LEFT JOIN wp1_term_taxonomy taxonomy ON taxonomy.term_taxonomy_id = relationships.term_taxonomy_id LEFT JOIN wp1_terms terms ON terms.term_id = taxonomy.term_id WHERE terms.name = "Restaurant" AND posts.post_type = "reference" AND posts.post_status = "publish" ORDER BY posts.post_date DESC LIMIT 0, 2;
This request returns 2 result in phpMyAdmin as execpted.
The return of get_results() is empty !!!
I already use $wpdb->get_results on other pages but with the request with only one joint.
Is it the problem ?
If anybody have an idea, feel free to help.
]]>I decided to use modified_date to see if I can get that changed first. It checks daily and compares post dates and if it is over a week old it should update the date to this monday’s date.
I got pretty far with it but I am finding it hard to test.
add_action('my_daily_event', 'update_jobdate');
function check_updates() {
if ( !wp_next_scheduled( 'update_jobdate' ) ) {
wp_schedule_event( time(), 'daily', 'update_jobdate');
}
}
add_action('wp', 'check_updates');
// do something everyday
function update_jobdates(){
global $wpdb;
//this monday
$this_monday = strtotime('Monday this week');
$newdate = $this_monday;
$newgmt_time = get_gmt_from_date($newdate);
$today = current_time('timestamp');
// Get all jobs
$jobs_list = $wpdb->get_results("SELECT ID, post_date, post_modified, post_modified_gmt FROM $wpdb->posts WHERE cat = 'job_listing' AND post_status = 'publish' AND post_type = 'post'", ARRAY_A);
if ( $job_list ) {
foreach ($job_list as $job_dates) {
// Get current date
$job_date = get_post_date( 'U' );
// Get the days difference
$difference = human_time_diff($job_date, $today);
if ($difference >= "6 days") {
// Update posts
$my_post = array();
$my_post['ID'] = '%s';
$my_post['post_modified_gmt'] = '$newgmt_time';
$my_post['post_modified'] = '$newdate';
// Update the post into the database
wp_update_post( $my_post );
}
else {
//do nothing
return false;
}
}
}
}
add_action( 'wp' , 'update_jobdates' );
?>
Anything obvious?
And how do I test?
Thanks in advance guys.
]]>In my search.php file I’m using WP Loop to display all search results. Because I’m using a lot of data in custom fields I use wpdb->get_results to retrieve any extra posts.
I would like to know if it is possible to add the results from wpdb->get_results into global WordPress results so that I can use only one loop and with sintax like have_posts(), the_post() ?
Any help?
Thanks
]]>add_action('show_etiqueta','et_get_post_user_etiqueta');
function et_get_post_user_etiqueta( $post_id ){
global $wpdb;
$result = $wpdb->get_results($wpdb->prepare("SELECT meta_value, count(*) AS countof FROM $wpdb->commentmeta WHERE meta_key='et_comment_etiqueta' GROUP BY meta_value ORDER BY countof DESC LIMIT 5", $post_id));
print_r($result);
return $result;
}
I call it here:
<?php do_action( 'show_etiqueta' ); ?>
But all I get as output is this:
Array ( [0] => stdClass Object ( [meta_value] => test [countof] => 3 ) [1] => stdClass Object ( [meta_value] => inprediscible [countof] => 1 ) [2] => stdClass Object ( [meta_value] => interesante [countof] => 1 ) [3] => stdClass Object ( [meta_value] => aqui va tu etiqueta [countof] => 1 ) [4] => stdClass Object ( [meta_value] => hurtest [countof] => 1 ) )
I tested the query in phpmyadmin to see if I get the result I want and it really gets the right result.
Can Anyone help me to have the right result displayed? tHank you
No match ???
Someone can help me ???
I have a problem while fetching rows from table. Some of my column name(into table) like 1,2,3,4 etc.I used following way to fetch results from database. Code is something like following..
$results=$wpdb->get_results(“SELECT * FROM mytable”);
if($wpdb->num_rows)
{
foreach ($results as $result)
{
echo $result->1; (Not Works)
echo $result->2; (Not Works)
echo $result->mycolname; (Works)
}
}
have any solution… thanks a lot.
]]>