Correct syntax to html php conversion

you are missing the three curly brackets in before wp_reset_postdata(). backup your code and replace with this. <?php $args = array(‘post_type’ => ‘menu’, ‘posts_per_page’ => 5, ‘post__in’ => $ids, ‘post_status’ => ‘any’, ‘orderby’ => ‘post__in’); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); if (is_page(538) ) … Read more

Multiple choice in a custom taxonomy

To display multiple authors, loop through the array of authors: function show_product_autor(){ $authors = wp_get_post_terms( get_the_ID(), ‘autor’ ); foreach($authors as $author) { $authorTeamPg = get_page_by_title( $author->name, ‘OBJECT’, ‘team’ ); $authorTeamPgLink = get_permalink( $authorTeamPg->ID); echo “<b>AUTOR: </b><a href=”https://wordpress.stackexchange.com/questions/289422/{$authorTeamPgLink}”>{$author->name}</a>”,'<br />’; } } To handle editors, the simplest solution IMO would be to make the taxonomy heirarchical and … Read more

Ajax return code 400

Here’s a base snippet I use for AJAX submits in WordPress, it might help you out: <?php if (isset($_POST[‘my_theme_ajax_submit’])) if ( wp_verify_nonce( $_POST[‘nonce’], ‘my_theme_ajax_submit’ ) ) my_theme_ajax_submit(); function my_theme_ajax_submit() { // do something // some php code that fires from AJAX click of #fire wp_mail( ‘[email protected]’, ‘my_theme_ajax_submit() fired’, time()); wp_die(); } ?> <button id=’fire’>Fire Something</button> … Read more

Woocommerce product download URL

<?php $downloads = $product->get_files(); foreach( $downloads as $key => $download ) { echo ‘<p class=”download-link”><a href=”‘ . esc_url( $download[‘file’] ) . ‘”>’ . $download[‘name’] . ‘</a></p>’; } ?> Check this.. Worked for me.

PHP Date display as time ago

There is a function for that: human_time_diff(). Use it like so: (U because we want the unix timestamp) <?php echo human_time_diff( get_the_time(‘U’) ); ?> If you want additional text, you can use the following <?php printf (esc_html__(‘%s ago’, ‘yourlanguageslug’), human_time_diff(get_the_time(‘U’))); ?>

is_page “range” for if statement?

I think you should create range as variable and set it to is_page() something like this should work. $range = range(310, 326); if(is_page($range)){ // your code.. } is_page() function can accept array as argument. And range() function return array. This example works fine for me.

How to sanitize my cookie name

Assuming $from_page is a string value and not an array or object, sanitize_key() should do the trick, it allows only a-z0-9_- and I believe is used for permalink. $cookiename = sanitize_key( ‘unrestrict_’.$from_page ); setcookie( cookiename, 1 … there’s a whole bunch of wordpress sanitizing functions, reference available in the docs.

Remove query string specific key value

[EDIT] This should work the way you wanted it to: $marca = get_query_var(‘marca’); $marca_arg = isset($marca) && is_array($marca) ? $marca : []; $url_base = remove_query_arg( ‘marca’ ); $n = count( $marca_arg ); foreach ($marcas_terms as $marca_term) { $selected = in_array( $marca_term->slug, $marca_arg ); if ( $selected ) { $marca_arg2 = array_diff( $marca_arg, [ $marca_term->slug ] … Read more

How to restrict page access to logged-in users?

How about this? function my_force_login() { global $post; if (!is_single()) return; $restricted_parent_id = 1 // Whatever id you are targeting. if ($post->post_parent == $restricted_parent_id && !is_user_logged_in()) { auth_redirect(); } } More info on post_parent and other conditional tags here: https://codex.wordpress.org/Conditional_Tags

Custom Template 404 for specific custom post type

This is going to track only post_type query var, but you also can add checks for query_vars of all your post_types or only ones you would like to get a custom 404 page for. add_filter( ‘404_template_hierarchy’, function( $templates ) { global $wp_query; if ( ” !== $wp_query->get(‘post_type’) ) { array_unshift( $templates, sprintf( ‘%s-404.php’, $wp_query->get(‘post_type’) ) … Read more