get_posts return only first result

// Get the category ID from url $catsearched = $_GET[‘product_cat’]; //printf($catsearched); $earth_radius = 6371; // Get products of category with in range distance $querystrShop = $wpdb->prepare(” SELECT productid AS post_id,(%d * ACOS(COS(RADIANS(%s)) * COS(RADIANS(phiz_geo_location.latitude)) * COS(RADIANS(phiz_geo_location.longitude) – RADIANS(%s)) + SIN(RADIANS(%s)) * SIN(RADIANS(phiz_geo_location.latitude)))) AS distance, phiz_postmeta.meta_value FROM phiz_geo_location JOIN phiz_term_relationships ON phiz_geo_location.productid = phiz_term_relationships.object_id LEFT JOIN … Read more

Get latest posts from multisite

There is actually a way to get posts from all multisite sub-sites. I do it with my “Multisite Media Display” plugin here https://wordpress.org/plugins/multisite-media-display/ . I use it to display all media items from my multisite to ensure that any submissions meet the site requirements. Works great. I have a similar plugin for posts, but it … Read more

get_the_category return empty inside loop

The problem is here: switch_to_blog($subsite_id); $blog_posts = get_posts(); restore_current_blog(); foreach( $blog_posts as $post ) { setup_postdata( $post ); get_template_part( ‘theme-partials/post-templates/loop-content/masonry’ ); } Your code fetches a number of posts, but then you switch back to the original blog! So now post number 5 means something completely different than it did before. You need to stay … Read more

How to get an array of pages ID by some page’s slug and all its children pages in get_posts() function?

You can use get_page_by_path() to get a Page’s WP_Post object using its slug (ie, its path), and then use that object to then get the array of child page IDs using get_children(). // First we’ll create the list of posts (pages) to exclude. $exclude = array(); $parent_page_obj = get_page_by_path( ‘abc’ ); if ( ! empty( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)