How can I get this code to only output one link?

You need to break both foreach loops not just one, so add break 2; after the echo. $mycats = array(106, 107); foreach (get_the_category() as $childcat) { foreach ($mycats as $mycat) { if (cat_is_ancestor_of($mycat, $childcat)) { echo ‘<a href=”‘.get_category_link($childcat->cat_ID).'”>’ . $childcat->cat_name . ‘</a>’; break 2; } } }

Getting URL Variables with a Rewritten Page (Login Page)

If you want instead of redirect to wp-login the user redirect to login page then use the following code. It will redirect user to login page where login form is present. add_filter(‘site_url’, ‘wplogin_filter’, 10, 3); function wplogin_filter( $url, $path, $orig_scheme ){ $old = array( “/(wp-login\.php)/”); $new = array( “login/”); return preg_replace( $old, $new, $url, 1); … Read more

301 redirect for wordpress permarlink

You may try this… RedirectMatch 301 ^/food$ http//:domain.com/food-for-healthy/ As per the syntax for RedirectMatch, the URL part can not be a regex. So, to achieve that you may use RewriteRule.

Custom field in a shortcode?

$post is global variable, so it’s not visible in this scope (and when you use $post in your code, you’re not referring to global $post variable but to local one) You should put global $post somewhere in your code. For example like this: … while ($loop->have_posts()){ global $post; $loop->the_post(); $output .= ‘<li><a href=”‘.get_permalink().'”><img src=”‘.get_post_meta($post->ID,’wpcf-udstiller-logo’,true).'”/></a></li>’; } … Read more

Multiple search template with separate stylesheets

I’ve never used is_page_template() but I have had good luck with is_page(‘new_search’) regardless of which conditional you use some things to check. Is the is_page_template(‘new-index.php’) working. you may test this by doing something like: if ( is_page_template(‘new-index.php’)) { wp_die(‘new search page’);} You should also use wp_register_style and wp_enqueue_style in your functions.php hooking in the the … Read more