WordPress.org

Support

Support » Plugins and Hacks » Hacks » How to set custom field value as post permalink..?

How to set custom field value as post permalink..?

  • Hi Guys,

    I have a plugin that sends out new posts to my various bookmarking accounts & uses the host site’s url as the post permalink, however there is an option to manually set this url to one of your choice eg that of the source site, by simply typing in the url required.

    Now as the site I’m working on is basically a RSS aggregator site, then I wanted to get the plugin to use the source url instead of the host sites url & thought the easiest way would be to create a custom field with the source url as the value.

    The problem I have is how to get this value assigned to the variable in the plugin that creates the permalink..?

    This is the section of code that I believe is responsible for the permalink;

    if (get_option('bml_linkbox') == "") 
    
                {
    
                $permalink = get_post_permalink($post_ID);
    
    	  }
    
    			else {
    
                         $permalink = get_random_BML(get_option("bml_linkbox"));
    
                		 }
    
            $permalink = urlencode($permalink);

    Now I figure the first line is checking for a manual entry as I mentioned earlier & when it doesn’t find one, then I believe line 3;

    $permalink = get_post_permalink($post_ID);

    is setting the permalink..? So I tried changing this line to;

    $permalink = get_post_meta($post->ID, "ex_url", true );

    ex_url being the custom field I created. But when I do this it doesn’t post out anything at all, although the url in the custom field is correct.

    Any help on this greatly appreciated as PHP really is not my strong point 🙁

    Cheers Steve

Viewing 2 replies - 1 through 2 (of 2 total)
  • Maybe $post needs to be declared global? Or try using get_post_meta($post_ID, "ex_url", true ) instead of $post->ID as first parameter.

    Hi bcworkz,

    thanks for the suggestion, but I’m afraid it still did not work !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to set custom field value as post permalink..?’ is closed to new replies.