Tag Info

Hot answers tagged

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 ...


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

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 ...


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.


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

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 ...


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

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 ...


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[] = ...


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

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 ...


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

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

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 ...



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