Custom query using WP_Query is not working

Its not clear what the goal is here, but here are some suggestions: In general, the pre_get_posts hook is not a good place to instantiate a secondary query to display HTML. Your current setup will result in an infinite-loop, because when you instantiate WP_Query within the pre_get_posts callback, you will instantiate it recursively, until you … Read more

What argument does my function need to echo get_results() query results

Why don’t you just do.. add_action( ‘wp_head’, ‘quick_qs_db_css’, 100 ); function quick_qs_db_css() { ?> global $wpdb; $table_name = $wpdb->prefix . ‘qs_css’; $db_css = $wpdb->get_results( ” SELECT qs_the_css FROM $table_name WHERE qs_css_id = 1 ” ); <style type=”text/css” id=”db-css”> <?php echo $db_css[0]->qs_the_css; //outputs null ?> </style> <?php } Seeing as you are using it everytime head … Read more

How can I use a specific wordpress page template if certain words are used in page title [closed]

You can adjust the template to use in the fly based on the type of page you’re viewing. https://codex.wordpress.org/Plugin_API/Filter_Reference/template_include add_filter( ‘template_include’, ‘portfolio_page_template’, 99 ); function portfolio_page_template( $template ) { if ( is_page( ‘portfolio’ ) ) { $new_template = locate_template( array( ‘portfolio-page-template.php’ ) ); if ( ” != $new_template ) { return $new_template ; } } … Read more

Get a page ancestor from a most viewed list

get_ancestors will return array form value. So if you talking about how to get and display that ancestors with link: <?php $arrAncestors = get_ancestors( $post->ID, ‘page’); $cntAncestors = COUNT($arrAncestors); if($cntAncestors > 0) { $parentPostId = $arrAncestors[$cntAncestors – 1]; $parentPageLink = get_permalink($parentPostId); $parentTitle = get_the_title($parentPostId); print ‘<li><a href=”https://wordpress.stackexchange.com/questions/243836/<?php $parentPageLink ?>” title=”<?php $parentTitle; ?>”><?php $parentTitle; ?></a></li>’; } … Read more

Calling a function with WP_Query only ever brings the first result

If you switch to get_posts you don’t have to worry about resetting the loop. function SliderBuilder( $categoryID ) { $args = array ( ‘cat’ => $categoryID, ‘posts_per_page’ => 3, ); $posts = get_posts( $args ); echo $categoryID; ?> <ul class=”blog-slider” id=”blog-slider”> <?php foreach ( $posts as $post ) { ?> <li class=”blog-slide” onclick=”location.href=”https://wordpress.stackexchange.com/questions/243846/<?php echo get_the_permalink( … Read more

SQL Query Search page

you can use WP_Query(); to query the results. it has an argument ‘s’ => $search_query, create an input, get the input value, store it in $search_query, then create a query, $query = new WP_Query( array( ‘post_type’ => ‘post’, ‘s’ => $search_query ) ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); // … Read more

Pull posts from all categories if quantity is not met?

I would start by creating an array to put your posts into, to create a counting system of some kind. Dump your list item output into that array, count it, and use the remaining count to call your second query. <?php $term = get_term_by(‘slug’, get_query_var(‘term’), get_query_var(‘taxonomy’)); $sticky = get_option(‘sticky_posts’); // Moved the base arguments into … Read more

How can I use two custom fields in WP Query

I solved with this $args = array( ‘posts_per_page’ => 6, ‘post_type’ => ‘post’, ‘post_status’ => ‘future’, ‘meta_key’ => ‘listorder’, ‘order’ => ‘ASC’, ‘orderby’ => ‘meta_value_num’, ‘meta_query’ => array( array( ‘key’ => ‘edition’, ‘value’ => 1, ), ), );