0

I wrote this couples of functions, that alternate a exploded Custom Field string with the post permalink:

(where the Custom Field should look like this: ex. Google++http//:google.com")

// Custom Permalink
function custom_permalink($url){
 global $post;
 $link = get_post_meta($post->ID,'link',true);
 if ($link) {
 $pieces = explode("++", $link);
 $url = $pieces[1];
 } else {
 $url = the_permalink();
 }
 return $url;
}
// Via Text
function via_text($url){
 global $post;
 $link = get_post_meta($post->ID,'link',true);
 if ($link) {
 $pieces = explode("++", $link);
 $url = ' <span><a href="'.$pieces[1].'">Via '.$pieces[0].'</a></span>';
 } else {
 $url = ' ';
 }
 return $url;
}

... which work all right when tested on a MAMP server, but when deployed they return:

"Warning: Missing argument 1"

Any idea why this might be happening?

asked Aug 27, 2012 at 22:42
2
  • Try to see at which line does this warning occur. Commented Aug 28, 2012 at 4:58
  • Turn on WP_DEBUG on your MAMP, see what it gives: codex.wordpress.org/Editing_wp-config.php#Debug Commented Aug 28, 2012 at 9:37

1 Answer 1

1

Ok... I figured it out... this happens when a class gets instantiated and theres no default argument for the constructor...

here are the working functions...

 // Custom Permalink
 function custom_permalink($url='') {
 global $post;
 $link = get_post_meta($post->ID,'link',true);
 if ($link) {
 $pieces = explode("++", $link);
 $url = $pieces[1];
 } else {
 $url = the_permalink();
 }
 return $url;
 }
 // Via Text
 function via_text($url='') {
 global $post;
 $link = get_post_meta($post->ID,'link',true);
 if ($link) {
 $pieces = explode("++", $link);
 $url = ' <span><a href="'.$pieces[1].'">Via '.$pieces[0].'</a></span>';
 } else {
 $url = ' ';
 }
 return $url;
 }

in case anyone is in need... what they do:

in case theres a post with the Custom Field 'link' (like so: Google++http://google.com) the function will replace the permalink with the Custom Link. So in the theme call: echo custom_permalink(); ... instead of the_permalink();

the via_text() function works a little different; it calls a span tag with the Custom Field 'link' exploded like so:

 <span><a href="http://google.com">Via Google</a></span>

hope this works for somebody else

:)

answered Aug 28, 2012 at 11:15
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.