get_posts not finding argument: post_name

Aha, despite there being a postmeta field of post_name->’slug’, the correct syntax (which mirrors that of WP_Query, is $args = array( ‘name’ => $postSlug, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’ ); $slugPosts = get_posts($args); Where ‘name’ is the key in the query (for posts, ‘postname’ for page). Doesn’t make much sense but might as well … Read more

How to Access Global $multipage or Global $numpages outside the loop?

Just inspect the current post content for ‘<!–nextpage–>’: function wpse_check_multi_page() { $num_pages = substr_count( $GLOBALS[‘post’]->post_content, ‘<!–nextpage–>’ ) + 1; $current_page = get_query_var( ‘page’ ); return array ( $num_pages, $current_page ); } On page 2 of 3 that returns: Array ( [0] => 3 [1] => 2 ) On an unpaged post it returns: Array ( … Read more

Using is_main_query to select custom post type on certain page

The is_home() conditional returns true when the currently displayed page is the blog posts index. If you want to target the site front page specifically instead, you need to use is_front_page(): function wpse83754_filter_pre_get_posts( $query ) { if ( $query->is_main_query() && is_front_page() ) { $query->set( ‘post_type’, array( ‘home_portfolio’ ) ); } } add_action( ‘pre_get_posts’, ‘wpse83754_filter_pre_get_posts’ ); … Read more

Perform query with meta_value date

I did something similar, the technique you need to use is called a meta query. Here is the query I wrote to get posts based on a date value stored as a custom field meta value. query_posts( array( ‘post_type’=>’post’, ‘order’=>’ASC’, ‘orderby’=>’meta_value_num’, ‘meta_key’=>’date_event’, ‘posts_per_page’=> -1, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘date_event’, ‘value’ … Read more

How to ensure “the_content” filter runs only for the main displayed content?

Try adding a condition to your filtering function that checks your post type against get_post_type. if ( ‘book’ == get_post_type() ) If you wish to apply this filter to pages as well, try is_singular() and include your custom post type(s) as an argument. is_singular(‘book’); This will return true if any of the following conditions are … Read more

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