WP multisite ACF get_field() restores to current site - wordpress

I'm getting really frustrated with this issue I am having with WP multisite.
The idea is, I have a multisite and it is here where all posts are created then just shared down to the other sites using ACF field.
Here is a part of the code where the issue happens:
switch_to_blog(1);
$person= get_posts( $args );
foreach($person as $post) {
echo get_current_blog_id(); THIS WILL DISPLAY 1
$person_info = get_field('person_info', $post->ID);
echo get_current_blog_id() ; THIS WILL DISPLAY THE CURRENT SITE, THE SITE JUST GOT RESTORED
}
restore_current_blog();
Can anybody help me figure out what is happening please?
TIA

Related

Change 'home' link in breadcrumb to specific page

I'm using the Avada theme, and trying to edit the breadcrumb Home link. It has to refer to another link. The wordpress given code isn't working. Someone got any idea?
Using original given wordpress code isn't working. The exact URL isn't doing the job, nor is the return get_permalink( $shop_page_id ).
Code below isn't working:
add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
function woo_custom_breadrumb_home_url() {
$shop_page_id = get_option( 'woocommerce_shop_page_id' );
return get_permalink( $shop_page_id ) ;
}
Hope anyone can help me to get this done using the Avada theme?

How can I add some posts in the homepage and have a blog page as well?

I am building my own - custom - theme in WP.
In my index.php, I have many static contents ( Don't know how to convert them into dynamic fields in WP yet, but I will learn this later ).
The issue is that I want to display a number of posts in the homepage 2 posts and below them a link to redirect the user to a blog page which displays the whole posts.
I searched a lot and I found a solution which is not doing what I want, it was about setting a static front-page and set the blog page as the Posts page under settings then reading.
After doing so, the whole static content - that was in my index.php doesn't appear on the homepage anymore and the homepage becomes an empty page and the whole content went to the blog page, which made me CRAZY!!
All I want to do; is to keep my static content and 2 of my most recent posts in the homepage and create a blog page which contains the whole posts.
Hope to find a solution for this Without Plugins.
Add This Snippet Code into your front-page.php or wherever you want to show 2 posts recently published.And Also a Blog Page Link to navigate the user to all blog posts..
$the_query = new WP_Query( array( 'post_type' => 'post',
'posts_per_page' => 2,
'orderby' => 'publish_date',
'order' => 'DESC'
)
);
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
the_excerpt();
the_author();
// add whatever you want
endwhile;
wp_reset_postdata();
echo 'See All Blog Posts Here : <a href='.site_url("blog").'>All Blog Posts</a>';
else :
esc_html_e( 'Sorry, no posts yet published.' );
endif;
?>
This is going to be a detailed answer to my problem to help anyone who might face the same problem, it will cover everything in steps for a WordPress newbie, like me! :D
As mentioned in my Question, my problem is that I want to display 2 posts in my index.php and make a separate blog page contains the whole posts.
The Most Detailed Solution:
1) Go to your index.php and use the normal posts loop:
<?php
// The Loop
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} // end if
?>
2) From WP Dashboard, go to Settings then Reading and change the Blog pages show at most value to 2 posts Or whatever number of posts you want.
Now, we've done the first step and show only a specific number of posts in our index.php, let's continue the steps to display the whole posts in our blog page.
3) Create a PHP Page called page-blog.php.
Notice: if you don't have a page.php you have to create it, for more information about how to create a custom PHP Page, I recommend #Adam's answer here.
4) Go to your WP Dashboard and create a new page called blog.
5) In your page-blog.php you need to add this snippet:
// Posts Query
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('posts_per_page' => 6, 'paged' => $paged );
query_posts($args);
// The Loop
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} else {
echo "Sorry, There is no posts to be displayed";
} // end if
?>
Notice: We used the same loop as we did before in index.php, only the new 2 lines of codes which above the loop is the new different thing here in our page-blog.php page
6) I set the posts_per_page to 6 because it is my blog page and I want to display more posts there. Set its value to whatever number you want, it depends on you
7) BOOM, it works and you did what you wanted, just like me!!
This problem seemed VERY COMPLICATED for me, but when I searched and read more information about this, I found that it is a VERY EASY to solve problem, and I hope this answer help you if you faced it!

woocommerce show the categories image on the page

im solving this for two days is there anyone there to help me. Im using Tweenty thirteen themes for wordpress customize it and i install the category listing plugins to show the image category but it sems on the side bar is no problem but in the content is showing this "Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\barfly\wp-content\plugins\woocommerce-category-widget\woocommerce-category-widget.php on line 445
"
Which version of woocommerce and wordpress are you using? Woocommerce are now on 2.3 and they under went lot of changes. Its not just about the foreach loop, even if you solved it, it would still need other changes.
What i would suggest is update woocommerce, wordpress and your listing plugin to the latest version. Secondly it looks like the category listing plugin you are using doesnot support the new version of woocommerce, Make sure it supports the latest version of woocommerce.
EDIT:
place this code within the loop, it will get thumbnail from the category and display them after the Category title.
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="" />';
}

wp_insert_post doesn't run plugins

I made a wordpress plugin which posts on your behalf . I use wp_insert_post() function to do so , but it ignores the other plugins which are supposed to run when you add a new article. One of those is NextScript's snap plugin. Auto Post Thumbnail doesn't run also. Anyone had this problem before?
On success, wp_insert_post returns the post ID, which you can use to further process the newly inserted content, e.g. in the case of Auto Post Thumbnail:
$post_id = wp_insert_post( $args );
if( function_exists( 'apt_publish_post' ) )
apt_publish_post( $post_id );

Showing comments from two blog post entries on a single page in wordpress

In my wordpress page School I have two different blog. let's say blog A and blog B. When use on either blog A or blog B he can make comment. Now I want to make the comments mutual of both blogs.
i.e
If someone comments on the blog A it should display like below:
on the blog A itself
on the School page
and also on the blog B
So no matter where user has comment on the above mentioned three pages comment go on all three pages.
You could use the rss feeds to get comments and load those into the page.
If it is a multisite you could take a look here.
If the sites are separate but on the same server you could make a connection to there databases and query the comments you need.
You will need to code something yourself at the very least.
You can get comments of a post by using WP_Comment_Query. A rough example:
<?php
$args = array(
'post_ID' => 1 //Add the postID of the post you need here
);
// The Query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );
// Comment Loop
if ( $comments ) {
foreach ( $comments as $comment ) {
// here you can display the comment in the way you want
echo 'Author: ' . $comment->comment_author . '<br/>';
echo '<p>' . $comment->comment_content . '</p>';
}
} else {
echo 'No comments found.';
}
?>
Do take a look at the article mentioned above. I don't know how you want to get the post_ID but that's up to you. Let me know if you need help.

Resources