How to access WP database inside ipn.php? [duplicate]
Try adding this to the top of your script: require(‘/path/to/httpdocs/wp-blog-header.php’); global $wpdb; Then you can run queries using: $sql = “Your SQL Query Here”; $wpdb->get_results($sql)
Try adding this to the top of your script: require(‘/path/to/httpdocs/wp-blog-header.php’); global $wpdb; Then you can run queries using: $sql = “Your SQL Query Here”; $wpdb->get_results($sql)
Just unsetting the cat variable probably isn’t enough. The pre_get_posts hook happens after the query variables have already been parsed. So there’s probably a tax_query with the taxonomy = category and the terms = your category. You’re already dumping the $query in your code, presumably for debugging. So, look at what you’re actually dumping. Do … Read more
There is no reason that query should behave differently on a single post page than on any other page. That is, there is no reason in the code posted. The only thing that I can think of would be that there is a filter interfering– perhaps a poorly written filter on pre_get_posts or post_limits. You … Read more
I figured out the answer to my own question (finally!). I’m using the NineToFive template and I guess by default there’s a limit on the number of search results that’s returned (I’m not sure if that’s a WordPress default; maybe someone can clarify that). I changed my query to this: $s = new WP_Query(array(‘s’ => … Read more
Use $post = get_post( id ); and then set the post like setup_postdata($post); and you can call the_content(); or the_excerpt();
This is an overly complicated approach. pre_get_posts will work for any query and there are numerous ways to control when/how the callback behaves: Add and remove the callback: function dummy_action($q) { } add_action(‘pre_get_posts’,’dummy_action’); $q = new WP_Query( array( ‘post_type’ => ‘post’ ) ); remove_action(‘pre_get_posts’,’dummy_action’); Use a self-removing callback: function dummy_action($q) { remove_action(‘pre_get_posts’,’dummy_action’); } add_action(‘pre_get_posts’,’dummy_action’); $q … Read more
Use the built in current_post and post_count vars with php’s modulus operator to check where you are in the loop and output markup at the appropriate time. if( $grid_loop->have_posts() ): echo ‘<div class=”row”>’; while( $grid_loop->have_posts() ): $grid_loop->the_post(); ?> <div class=”col-xs-3 box”> <p><?php the_title(); ?></p> </div> <?php // if this is the third post // and … Read more
If I’m not missing something, the below should work for you. It is pretty much straight from the Codex: WP_Query – Custom Field Parameters. Do it like this: $args = array( ‘post_type’ => ‘post’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘color’, ‘value’ => ‘red’, ‘compare’ => ‘=’ ), array( ‘key’ => ‘size’, … Read more
While WordPress does currently support multiple orderby it doesn’t actually support multiple order respectively. This was fixed very recently, see ticket #17065 (Independent ASC/DESC in multiple ORDER BY statement.) and will be available in 4.0 release with new array syntax: ‘orderby’ => array( ‘title’ => ‘DESC’, ‘menu_order’ => ‘ASC’ ).
First off: You theoretically can query the WordPress database with raw MySQL, of course. See wpdb‘s get_results method. That might save you a second query, but obviously will not return proper WP_Post objects. That being said, nope, if you want to use WP_Query, you will not get around using two queries. I’d still recommend it … Read more