global $wpdb;
$table_name = $wpdb->prefix . "posts";
$add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));
// UPDATE wp_posts SET post_parent=370 WHERE ID=84887
In next line, i need to get the post again and then perform some functions. I am doing it like this
$post = get_post( 84887 );
But instead of returning updated values, i am getting the old post_parent value in return. Like below
WP_Post Object
(
[ID] => 84887
[post_author] => 2
[post_date] => 2020-02-27 10:55:11
[post_date_gmt] => 2020-02-27 10:55:11
[post_content] =>
[post_title] => MyTeam
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => allus-cu
[to_ping] =>
[pinged] =>
[post_modified] => 2020-08-24 19:03:02
[post_modified_gmt] => 2020-08-24 19:03:02
[post_content_filtered] =>
[post_parent] => 844 // This value is not correct. This should be 370
[guid] => https://train.localdev.com/?post_type=wc_memberships_team&p=84887
[menu_order] => 0
[post_type] => wc_memberships_team
[post_mime_type] =>
[comment_count] => 0
[filter] => db
)
I have checked in Database and in database, post_parent value is updated one.
Complete Code in all together:
global $wpdb;
$table_name = $wpdb->prefix . "posts";
$add_plan_to_team = $wpdb->update( $table_name, array( 'post_parent' => '370' ), array('ID'=> '84887'));
if($add_plan_to_team){
$post = get_post( $team_id, 'OBJECT', 'db' );
echo '<h1> team_updated </h1>';
print_r($post);
}
Please tell me how can i fix it.
]]>It seems that the gardian of your condition where you force using menu order is not complete in the ‘pre_get_posts’ action.
If I use suppress_filters with true, wont work.
I think it will be better if the gardian is
isset($wp_query->query[‘suppress_filters’]) && !$wp_query->query[‘suppress_filters’] )
What do you think.
Yves
]]> $args = array(
'numberposts' => '15',
'post_status' => 'publish',
'post_type' => 'aec_events',
'meta_key' => 'start_date_time',
'orderby' => 'meta_value',
'order' => 'ASC'
);
Unfortunetly post with start_date_time in the past are even displayed.
How can I filter this so only posts with meta_value >= Today are displayed?
Thank you for answer
Andreas
I’m trying to synchronize my latest post to local social network. The code I searched from internet could synchronize the latest post from default post type “post” only. However, I still have other 3 custom post types, let we say “experience”, “deal”, “value”. I believe there should be some code to be added at the beginning, but I don’t know how to do.
Could somebody help, thank you!
if(get_post_meta($post_ID,'weibo_sync',true) == 1) return;
$get_post_info = get_post($post_ID);
$get_post_centent = get_post($post_ID)->post_content;
$get_post_title = get_post($post_ID)->post_title;
if ($get_post_info->post_status == 'publish' && $_POST['original_post_status'] != 'publish') {
$appkey=''; /* */
$username='';
$userpassword='';
$request = new WP_Http;
$keywords = "";
/* get the thumbnail picture */
$url = get_mypost_thumbnail($post_ID);
/* if success, add weibo_sync to avoid the post re-sync to weibo again when update */
add_post_meta($post_ID, 'weibo_sync', 1, true);
}
}
add_action('publish_post', 'post_to_sina_weibo', 0);
]]><h2 class="bluebottom"><?php $categories = get_the_category(); foreach($categories as $category) { echo $category->name . ' '; } ?></h2>
<ul>
<?php
global $post;
$category = get_the_category($post->ID);
$category = $category[0]->cat_ID;
$myposts = get_posts(array('numberposts' => 99, 'category__in' => array($category), 'post__not_in' => array($post->ID),'post_status'=>'publish'));
foreach($myposts as $post) :
setup_postdata($post);
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endforeach; ?>
<?php wp_reset_query(); ?>
</ul>
How would I modify this code so the <h2></h2> at the top only appears if there is more than one post in the category?
]]>Product (custom post type)
–>Brand (custom taxonomy)
——>Brand A (custom term)
——>Brand B (custom term)
–>Department (custom taxonomy).
——>Department A (custom term)
——>Department B (custom term)
Each product always has to have one brand AND one department. However, there may be a few products in each brand.
So, I need to do a list that shows me the all the products that matches both a specific brand AND a specific department, and also that let me print the name of the brand. i.e: In department A we have 3 products that matches Brand A.
Is there any way to do it? I’m able to filter either one a brand or a department, but not both at the same time.
Thanks!
]]>I’m a bit of a novice so if you can explain I’d gladly appreciate it!
<?php $posts = get_posts('category=3&orderby=date&numberposts=3'); foreach($posts as $post) { ?>
<a href="<?php the_permalink() ?>" target="_parent">
<div class="aligncenter" style="display: block;">
<?php the_post_thumbnail( 'thumbnail', array( 'class' => 'img-responsive' ) ); ?>
</div>
<h3><?php the_title(); ?></h3></a>
<?php while (have_posts()) : the_post(); ?>
<?php echo excerpt(15); ?>
<?php endwhile; ?>
<a href="<?php the_permalink() ?>" class="blue"" target="_parent">
Read More</a>
</div>
<?php } ?>
This is on the page multiple times
and my function.php
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('<code>\[[^\]]*\]</code>','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
]]>I’m using this code, (found here), to add the content into an horizontal accordion that I’ve added to sidebar.php, (I’m not using any kind of widget, because I don’t need them form this specific project):
<?php
$my_id = 129;
$post_id_129 = get_post($my_id);
$content = $post_id_129->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
?>
and it works perfectly, (see here, just open the “La Storia” tab in the horizontal accordion; the original page from which I’m getting the content is here), but I’m not getting the whole formatting: as you can see, the text is bold where I need it to be, but the breaks are missing.
I’ve already added this into my functions.php:
<?php
// get_the_content with formatting
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
?>
but, while it works like a charm if I use it into a text widget, it’s not workin right now.
Thanks in advance for any help you may give me and have a good day/night!
]]>function get_woo_commerce_products() {
query_posts('post_type=product&showposts=-1&');
$ret_array= array();
while (have_posts()) :
the_post();
$postId = get_the_ID();
$nextPost= get_post($postId);
if ( !empty($nextPost) ) {
$ret_array[] = array( 'ID'=> $nextPost->ID, 'title'=> $nextPost->post_title );
}
endwhile;
return $ret_array;
}
I got the list I need but also I see that similar list is printed at below of page.
For posts using “showposts=-1” parameter in calling of query_posts helped me, but seems not for woo commerce products?
Which is the correct way ?
https://www.ads-software.com/plugins/woocommerce/
]]>When using the get_post method (or get_posts and the respons is one post only) they API fails to return a JSON object and instead redirects me to the post’s page.
Is there a way to make it stop doing that?
Thanks!
https://www.ads-software.com/plugins/json-api/
]]>