Adding custom shortcode to page leads to page without styling

Shortcodes need to return their values, but the_content() echoes the post content. So you have two options. First is to capture all output and then return it at the end: ob_start(); // Start capturing output; while( $loop->have_posts() ) { $loop->the_post(); the_content(); }; wp_reset_postdata(); return ob_get_clean(); // Return captured output; That will be the cleanest way … Read more

First post in loop displays twice

The else of the $change % 5 == 0 also runs when $change is a 1 and that is why the first post is displayed twice. You could fix it by changing <?php $change++ ?> <?php endif; ?> <?php if ( $change % 5 == 0 ) : ?> to <?php $change++ ?> <?php elseif … Read more

Query posts only shows 1

OK this is the thing: I used a query $args = array( ‘post__in’ => array($userPostsInternal), Taking the fact the following is a string var_dump($userPostsInternal); -> string(13) “128537,128545” I thought declaring the array here would work array($userPostsInternal) But it’s not, therefore thanks to a comment, suggesting me to explode $userPostsInternal converting the string into an array, … Read more

how to use transient method?

First, you don’t need a raw SQL query, and by using one you give up all of WP’s optimisations. For example, if you run the query twice, it runs twice. If you had used WP_Query to getch those posts though, it would save them the first time to avoid making additional queries. It’s even possible … Read more

Pagination in category.php not functioning

if your aim is to restrict the category archive to your post_type ‘video’ and to 6 posts per page, do not edit category.php, rather use ‘pre_get_posts’ https://developer.wordpress.org/reference/hooks/pre_get_posts/ example code for your case: add_action( ‘pre_get_posts’, ‘category_post_type_video_custom’ ); function category_post_type_video_custom( $query ) { if ( ! is_admin() && $query->is_main_query() ) { // Not a query for an … Read more

Carousel slider with WP_Query to show 3 posts on each slide

Despite your question is a generic PHP programming problem, what you’re trying to do can be achieved like so, where the key is the $i which is a custom while counter: <div class=”carousel-inner” role=”listbox”> <?php if ( $popular_services->have_posts() ) : $i = 0; // add this counter while ( $popular_services->have_posts() ) : $popular_services->the_post(); ?> <?php … Read more

Getting Custom Field value in WP_Query

You need to define the $post global variable if you want to access its ID property: function excateg($categ) { global $post; $recent = new WP_Query(“cat=$categ&showposts=1”); while($recent->have_posts()){ $recent->the_post(); $imageurl = get_post_meta($post->ID, ‘post-img’, true); } } Use it after the_post() because that function will set up that variable. Alternatively you can use the $recent->post property instead of … Read more

Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce

I passed query strings to the URL of the category page to display the tags within that category. This is what I did to solve the same problem function displayLocationDropdown() { if(!is_product_tag()){ $html=””; $html .= ‘<form class=”location-select” method=”post”>’; $html .= ‘<select id=”location-selector” name=”location” class=”location”>’; $tag = wp_tag_cloud( array( ‘format’ => ‘array’, ‘taxonomy’ => ‘product_tag’ ) … Read more

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