Advanced Custom Fields – Relationship post foreach query

Use the old method of adding the relationship field -> Post Object <?php while (have_posts()) : the_post(); ?> <div class=”entry-content”> <h1 class=”content-headline”>Package: <?php the_title(); ?></h1> </div> <div class=”package-description” style=”padding:15px 10px;background:white;”> <?php the_content(); ?> </div> <?php $posts = get_field(‘package_items’); if( $posts ): ?> <ul> <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) … Read more

How do you display the number of a post in a query?

Order number of the post in main query would be $wp_query->current_post + 1 (if I remember right it counts from zero, but try and see). 🙂 Note that literally your example is ordered list, which might or might not have been intended via Markdown. In that case you need to adjust your loop for appropriate … Read more

wpdb query with dynamic column name?

This is simply a syntax error by the looks of it. You are using ” to open the string, and ‘ to close it. Use this: $which_column = ‘phone’; $data_check = $wpdb->get_var(“SELECT ” . $which_column . ” FROM wp_shopping_preferences WHERE wp_user_id = ‘$id'”); Fun fact: when using double quotes (“), you can directed insert a … Read more

Re-sort get_posts query results

Reordering the way you want is really pretty trivial. Proof of concept: $p = array(1,2,3); var_dump($p); array_push($p,array_shift($p)); var_dump($p); With the WordPress code: $p = get_posts(‘posts_per_page=3’); array_push($p,array_shift($p)); var_dump($p); To make it more interesting, you can do the same with a filter. Since get_posts() uses wp_query() you can use the post_results hook to reorder the results. function … Read more

Wrap/close ‘query’ for a first-letter ordered listing of posts

The problem is that each time you start a new letter, you don’t close the list of the previous one. Inside your check if ($this_letter != $curr_letter), before the echo, you have to add a </ul> in all cases except when $curr_letter is empty (the first letter). if ($this_letter != $curr_letter) { if(” != $curr_letter){ … Read more

Querying with WP query using meta key price

‘meta_value_num’ – Order by numeric meta value (available with Version 2.8). Also note that a ‘meta_key=keyname’ must also be present in the query. This value allows for numerical sorting as noted above in ‘meta_value’. Try to use like this : $args = array ( ‘post_type’ => ‘product’, ‘post__in’ => $post_ids, ‘posts_per_page’ => -1, ‘order’ => … Read more

Updating with $qpdb->query() always returns 0 rows affected

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 … Read more

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