How to get a custom post with the largest ID (not the last post by date)

Turns out, I was kind of wrong when I tried to get the largest ID. What I needed was to get posts by, and then to sort by, the order number itself! Here’s what I came up with: $num_args = array( ‘post_type’ => ‘my_store_order’, ‘post_status’ => array(‘mystatus_1’, ‘mystatus_2’, ‘mystatus_N’), ‘numberposts’ => 1, ‘meta_query’ => array( … Read more

get_posts() SQL Injection

If not, how do I clean the incoming variables? In most cases you don’t, get_posts calls WP_Query internally, and WP_Query performs some sanitization, namely via wpdb->prepare. However, for what you’re trying to do, this is the wrong approach. Just use a standard search.php template with a standard post loop, and use input fields that have … Read more

get_posts wont produce a list of custom type from a given category [duplicate]

I’m assuming ‘news_category’ is a custom taxonomy; if not, and if you have simply created a new post category called ‘news_category’, it will only work if you add support to your custom post type. Be aware though that this will add complexities to your feeds and queries, as well as affecting how category posts show … Read more

php loop error for count posts in category

I have a working solution now… finally! <?php foreach ( $categories as $category ) { // If there is only one post available, go directly to the post if($category->count == 1) { $all_posts = get_posts($category); echo ‘<div class=”item”><h4 class=”item-title”>’ . get_the_title($all_posts[0]->ID) . ‘</h4><a href=”‘ . get_permalink($all_posts[0]->ID) . ‘”>Read more</a></div>’; } else { echo ‘<div class=”item”><h4 … Read more

Form checkbox value going to dynamic URL

I am no expert but you are submitting multiple checkboxes with the same name attribute. Your current form GET action will return the url params like this for example… http://www.urltoshow.com/ville/paris?style=Classique&syle=Luxe So because there are 2 usages of param style in the url above, it means PHP $_GET[‘style’] will only return the last getted param value. … Read more

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