Tag Info

New answers tagged

0

If you take a look at the category parameters of WP_Query, you'll see that you can use either cat=-12 or category__not_in' => 12 to exclude a category with ID 12 in your custom query. I just also want to point out a few things here. showposts is depreciated, you should be using posts_per_page. Also 'showposts=6' . '&paged='.$paged is wrong. You ...


1

rearrange your code and use post_count; example: <?php $movieNumber = 1; $today = date('Ymd'); $posts = array ( 'post_type' => 'movie', 'posts_per_page' => -1, ); $loop = new WP_Query( $posts ); ?> <div id="posters<?php echo $loop->post_count; ?>"> ...


0

Simply declare a variable above like $i=0; and use $i++ in while loop echo $i; where you want to show number of posts displaying. may it will work


0

Before your you have to create a new query then count the results: global $wpdb; $count = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type='movie'"); <div id="posters<?php echo $count; ?>">


0

Hope This will help <ul id="slider2"> <?php $args = array( 'post_type' => 'jobs', 'posts_per_page' => 15 , 'order' => 'ASC' ); $loop = new WP_Query( $args ); ?> <?php while ( $loop->have_posts() ) : $loop->the_post(); global $post; ?> <li> <h4><?php the_title(); ?></h4> <?php ...


0

This is untested, but I think it should work. Add the filter in pre_get_posts if it's your post type archive, otherwise remove it for any queries that follow the post type archive main query. function wpd_add_posts_orderby( $query ){ if( $query->is_post_type_archive('your-cpt') ){ add_filter('posts_orderby', 'edit_posts_orderby'); } else ...


0

I wouldn't say it's "easy", but any complex queries like the one you have that can't be handled via the API, WP_Query, or its filters should use the wpdb class. global $wpdb; $rows = $wpdb->get_results( " SELECT p1.meta_value as avg, p2.meta_value as total, p1.meta_value * p2.meta_value as product FROM ...


0

Since I don't have enough points to comment, I'll just make this an answer. What are you trying to use these queries for? It might be much more simpler to use the built in functions of wordpress. If you're adamant, I can't say much for making this much more easy in wordpress, but you could try using a PHP to MySQL framework, like medoo. That framework ...


1

Never use query_posts, use pre_get_posts to modify any main query. function wpd_exclude_author_category( $query ) { if ( $query->is_author() && $query->is_main_query() ) { $query->set( 'category__not_in', array( 42 ) ); } } add_action( 'pre_get_posts', 'wpd_exclude_author_category' );


-2

Well, assuming the post content will be provided by Youtube embedded code, a change in the regular expression is needed. The function must obtain the source of the iframe. So would be as follows: function get_thumbnail_fromyoutube( $size = 0 ) { global $post, $posts; $youtube = ''; $get_url = preg_match_all('/src="([^"]+)"/', $post->post_content, ...


0

It's a little hard to untangle this, but I'll try to address your points one by one. create a separate 404.php page to control the output of that page. (and the silence about any attempt to do it otherwise) 404.php template controls presentation of 404 page. This is highly in line with rest of WP template hierarchy. It's not mandatory either, without ...



Top 50 recent answers are included