Get wp_get_attachment_url outside of loop

if the result you’re looking for is a printout of the URL, like in your example, then this should work: $page_id = get_queried_object_id(); if ( has_post_thumbnail( $page_id ) ) : $image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $page_id ), ‘optional-size’ ); $image = $image_array[0]; else : $image = get_template_directory_uri() . ‘/images/default-background.jpg’; endif; echo $image;

wordpress query – orderby child post date

You should be able to do this with the get_children function (see the codex), $ticket_id = 34; // assume you want to retried the replies of ticket post id=34 $args = array( ‘post_type’ => ‘support_tickets’, ‘numberposts’ => -1, ‘post_parent’ => $ticket_id, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’ ); $replies = get_children( $args ); Assuming that … Read more

WP_Site_Query vs. WP_Network_Query in WordPress 4.6

When you set WordPress to multisite, in an “out of box” fashion, you create a single network of sites. Let’s, say, a network of food blogs. With plugins like WP Multi Network you can set up multiple networks. You could split that food blogs network into several networks: mediterranean food blogs, brazilian food blogs, thai … Read more

Query custom post type by custom field

You got it pretty close. Here’s a working example of what you’re trying to do: class Wpse_126374 { public function __construct() { add_action( ‘init’, array( $this, ‘rewrites’ ) ); add_action( ‘pre_get_posts’, array( $this, ‘pre_get_posts’ ) ); } public function rewrites() { add_rewrite_tag( ‘%parent_id%’, ‘(\d+)’ ); } public function pre_get_posts( $query ) { // Don’t run … Read more

Is there any difference between hooks posts_where with posts_join and posts_search performance wise?

All of these hooks are called in a similar fashion and get passes similar data. Under normal circumstances there should be no meaningful performance difference between them. One scenario I can think of is that if you aren’t properly targeting your code to specific queries and it runs in every query then posts_search might fire … Read more

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