gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
please create a php conditional in wordpress to check if the post type "wpslstores" is…
- User
please create a php conditional in wordpress to check if the post type "wpsl_stores" is not "new-location" slug: Get Directions
- Assistant
Certainly! If you want to conditionally display the div only when the current post type is
wpsl_storesand the post slug is NOTnew-location, you can do something like this in your WordPress template:php<?php if ( get_post_type() === 'wpsl_stores' && get_post_field('post_name', get_the_ID()) !== 'new-location' ) : ?> <div class="card-footer border-0 bg-transparent p-0"> <a href="<?php echo esc_url($google_link); ?>" target="_blank" class="btn cmg-btn-primary w-100">Get Directions</a> </div> <?php endif; ?>Explanation:
get_post_type()returns the current post type.get_post_field('post_name', get_the_ID())obtains the slug of the current post.- The condition checks if the post type is
wpsl_storesand the slug is notnew-location. esc_url()is used for safe output of URLs.
Place this code where you want the conditional output in your template file.