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

wordpress ajax is not working for dropdown selection

The first issue I see is the ajax url is incorrect. Your wp_localize_script() has the handle name ‘main’, not ‘ajax_object’. url: main.ajaxurl Also, where is the callback code to handle the get_program_by_category ajax action? You’re missing two actions. add_action( ‘wp_ajax_my_action’, ‘my_action_callback’ ); add_action( ‘wp_ajax_nopriv_my_action’, ‘my_action_callback’ ); See the WordPress Codex to learn more about using … Read more

Adding an IF ELSE to a function

You can write this code like below- <?php $element = get_queried_object_id(); if (!empty($element)) { $terms = get_terms([ ‘taxonomy’ => $element->taxonomy, ‘parent’ => $element, ]); echo ‘<div style=”height: 200px; text-transform: uppercase; border:1px solid #666666; padding:10px; overflow-y: scroll;”> <div class=”breaker-small”>Refine Search</div>’; foreach ($terms as $term) { echo ‘<p class=”filters”><a href=”‘ . get_term_link($term) . ‘”>’ . $term->name . … Read more

How to make an If Else on Excerpt Filter

Here is the solution that seemed to work. Thanks Tom function new_excerpt_more($more) { global $post; $thePostID = $post->ID; if($thePostID == 1128) { return ‘…<a class=”readmore” href=”‘. get_permalink($post->ID) . ‘”>Watch Video &raquo;</a>’; } else { return ‘…<a class=”readmore” href=”‘. get_permalink($post->ID) . ‘”>Read more &raquo;</a>’; } } add_filter(‘excerpt_more’, ‘new_excerpt_more’);

Only Show One Category Name Per Post

You need to pass the category ID into get_category_link() <a href=”https://wordpress.stackexchange.com/questions/244678/<?php echo esc_url( get_category_link( $category[0]->term_id ) ); ?>”><?php echo $category[0]->cat_name; ?></a> Here’s the whole thing put together <?php $query = new WP_Query( array( ‘posts_per_page’ => 2, ‘categories_per_page’ => 1, ) ); while ( $query->have_posts() ) : $query->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/244678/<?php the_permalink(); ?>”><?php the_title(); ?></a></li> <?php … Read more