Tag Info

Hot answers tagged

4

The function get_the_time is only designed to work either in the main WordPress loop or a custom loop using WP_Query, so the way you are using it won't work correctly. The following is the right way to use it, using a custom WP_Query loop: <?php // Get years that have posts $years = $wpdb->get_results( "SELECT DISTINCT YEAR(post_date) AS year FROM ...


2

Your logic in your code is wrong. Read your code in plain English. If the current post is number 3, show my custom content, else, show the posts as normal. What you want is the following If the current post is number 3, show my custom content. Show all my posts as normal To achieve this, you need only wrap your custom content in your ...


2

query_posts - You should never ever use query_posts. Apart from what @Rarst has said, the really big issue with query_posts is, it breaks the main query object ( stored in $wp_query ). A lot of plugins and custom code relies on the main query object, so breaking the main query object means that you are breaking the functionalities of plugins and custom code. ...


1

You are invoking an infinite loop, because you are calling WP_Query inside WP_Query, which is where the hook resides, so you are hooking it into parse_query over and over again. To avoid it, put the following at the beginning of your callback function: // avoid infinite loop remove_action( 'parse_query', __FUNCTION__ ); Additional note, it might just be ...


1

as ChrisL said in the comments, you should add order and orderby to your arguments : $args = array( 'post_type' => 'totem', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' );


1

wpdb uses PHP's mysqli_affected_rows() or mysql_affected_rows(), which can be disabled via an argument in php.ini. I am guessing that that is what has happened. Check the disabled_functions line in your php.ini file and remove the references to those function. Of the top of my head, I am not sure if extensions like Suhosin mess with that function but that ...


1

In the case that the start_date custom field only exists for the event post type, this works: $query->set( 'meta_query', array( 'relation' => 'OR', array( 'key' => 'start_date', 'compare' => 'NOT EXISTS', ), array( 'key' => 'start_date', 'value' => $today = date( 'Ymd' ), 'compare' ...


1

To load admin scripts only on your pages, you should use the $hook-parameter: function enqueue_scripts( $hook ) { if( 'my-page' != $hook ) return; wp_enqueue_script('jquery'); wp_enqueue_media(); // etc... } add_action('admin_enqueue_scripts', 'enqueue_scripts'); Concerning the loading problem. This seems to be still an open problem. The ...


1

For anyone struggling with this. 'orderby'=>'post__in' makes this work. <?php $successful_musics_array = array('1682', '1684', '556', '1793', '558', '1788', '320', '1190', '1865', '1125', '1863', '1540'); $query = new WP_Query( array( 'post_type' => 'songs', 'posts_per_page' => '15', 'post__in' => $successful_musics_array, ...


1

For example if there are 10 custom posts, and No. 1 is the oldest, and they happened to select the 3rd oldest one, they want it to say "No. 3". There is a more elegant way than that function: $args = array( 'post_type' => 'book', 'fields' => 'ids', 'ignore_sticky_posts' => true, 'orderby' => 'post_date', 'order' => 'DESC' ...



Only top voted, non community-wiki answers of a minimum length are eligible