Tag Info

New answers tagged

3

Yes, it is possible, but it is a bit of a pain. Looking at the codex page, only arguments of note are number and offset. We need these two to create our paginated pages. First, we set the $paged parameter, which is the current page: $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; Then number of comments to display: $number = 3; ...


2

Sebastien's answer got me on the right track. I should not be using the_author, because I am not looking for the author of a post (My query is not returning a post, but a user), rather the name of the user. I changed: echo get_the_author($spost->ID); to echo $spost->display_name;


2

get_the_author() takes no arguments and must be used within the Loop (I guess it's the case). /* get_the_author($spost->ID); Replace this. */ get_the_author(); // By this.


1

I'm not quite sure what you want to do as frankly, your terminology is a bit scrambled, and you example shortcode is also quite a mess. Before I start, you should start of by checking the following very important links Shortcode API WP_Query You should first start of by defining your attributes (and their defaults) which you need to use and pass to the ...


-1

I use this: add_action('pre_get_posts','search_filterr');function search_filterr($query) { if ( !is_admin() && $query->is_main_query() ) { if ( $query->is_search ) { $arrs[]='post'; $query->set('post_type', $arrs ); query->set('category__in', $CAT_ID); } ...


0

Found the problem. In my args, I should have included this line: 'post_type' => array( 'one', 'two', 'three', 'four', 'five', 'six' ), above the 'tag' arguments


0

You can still do the AS with $wpdb, I find it still makes stuff look cleaner. You can use the $wpdb->prepare() method for sanitation. Are you looking for something like this? function combined_downloads($post_id) { global $wpdb; return $wpdb->get_var($wpdb->prepare( "SELECT SUM( meta_value ) FROM $wpdb->postmeta AS m LEFT JOIN ...


3

The insert method of $wpdb already scapes the data taking care of SQL injection. What you should worry about is about data sanitization and validation. For exmpla: Sanitization What type of data do you accept in $votes? A integer value? If so, be sure $votes contains a integer value. You cuold do it, for exmaple, using intval function from PHP. This is ...


2

wpdb::insert already protects against SQL injection, it's a wrapper for wpdb::prepare For insert(), you can pass a third "formats" argument for extra sanitization: $wpdb->insert( 'votes', array( 'votes' => $votes, 'competition' => $competition, 'uid' => $uid ), array( '%s', // $votes will ...


0

Turns out setting explicity posts per page did if for me.


0

The loop in a page loads only the content of the page. Thus you see only one post. You have to set up a "Page of Posts". You can find basic examples in the codex at Page Templates. But using it as static front page results in some problems. The links to follow pages will not work. You have to evaluate get_query_var('page') instead of ...


0

If you set the fields argument to ids in your query it will return only post IDs which you can then pass to other functions to fetch the data you need. Though that may save memory at the cost of increasing queries to the database.


1

You second approach (EDIT 2) is quite buggy and inefficient unfortunately. Also, you are not going to do this in one query. As I already stated, you need to look at the approach in this answer I have recently done. You were almost there in your first edit, the only problem is, you cannot do this in one query, you will have to do two, one to get the ...


0

Your syntax is slightly off - $episodes is an instance of WP_Query, not an array. If you want a full-blown loop for using all template tags, use: while ( $episodes->have_posts() ) { $episodes->the_post(); the_title(); // Episode title the_content(); // Episode content } wp_reset_postdata(); // Restore current episode Otherwise you can ...


0

Here is how I implemented this: function getUsers($args = array(), $count = false) { // Default behaviour is to return full user information $method = 'get_results'; // If count is true then change the WP_User_Query method // and limit the fields SELECT'd to 'ID' to speed up the query if($count === true) { $method = 'get_total'; ...


2

I finally got it. First mistake was to process the same function twice. I've called it once after the function and one more time in ajax action. So when using the ajax call, the function got executed twice. In the example from the OP, this is not a problem at all, because it is simplified to do only one thing, but in my real code it does much more and can ...


1

AJAX is not magical and when you request url X you will receive the same HTML for that url if you do it from the browser address bar, link or ajax. Therefor, if you want different response then the HTML you can not use the same url for the ajax request as in the link. Wordpress has a special "end point" to handle ajax request - admin-ajax.php and all ajax ...


1

Make link like this <a href="http://example.com/?reaction=smk_remove_post&id=1226&_nonce=7be82cd4a0" data-id="1226" data-nonce="7be82cd4a0" class="smk-remove-post">Remove post</a> And jQuery $('.smk-remove-post').on( 'click', function( event ){ event.preventDefault(); var _this = $(this); var data = { 'action': ...


1

I'm currently busy with an extensive navigation plugin for single posts and pages which I hope to release in future which will do the same exact thing which you are after. The integral part is using a date_query in a custom WP_Query to fetch the adjacent posts according to the parameters passed to it. Here is an idea coming from the plugin To accomplish ...


2

I agree with Rarst about the WEEK function, but be sure to also use YEAR as well to order the posts. So your order by would look something like this: ORDER BY YEAR($wpdb->posts.post_date) DESC, WEEK($wpdb->posts.post_date) DESC, $wpdb->postmeta.meta_value+0 DESC Of course, this is still pulling all posts, so you might also want to just limit the ...


1

This is more of an MySQL question than WordPress one. You are already using date functions there, from a quick check there is (unsurprisingly) one for WEEK(date[,mode]), you could use in similar fashion for order.


1

You could do it for example like this: function wpse182116_get_categories_starting_with($word) { $categories = get_categories(); if (!empty($categories)) { $relevant_ids = array(); foreach($categories as $c) { $cat_name = $c->name; if(substr($cat_name, 0, strlen($word)) == $word) { $relevant_ids[] = ...


0

You can try this code below $args = array( 'orderby' => 'name', 'order' => 'ASC', 'name__like' => '%LIKE%', 'description__like' => '%LIKE%', ); $terms = get_terms( array( "taxonomy" ), $args ); See more in Codex


0

The global $wp_query (in this case its the $query var) holds the $current_post which is available in the loop and tells the index of the current post ( $wp_query->current_post ). The $wp_query->post_count tells the number of posts being displayed in the loop, and this actually becomes a simple arithmetic solution that will work no matter how many posts the ...



Top 50 recent answers are included