Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1079 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Wordpress / PHP Help

Thread title: Wordpress / PHP Help
Reply    
    Thread tools Search this thread Display Modes  
02-04-2012, 04:22 PM
#1
astereo is offline astereo
astereo's Avatar
Status: Member
Join date: Jun 2005
Location: east coast, usa
Expertise: design,development, & WP
Software: Photoshop, Illustrator, WP
 
Posts: 421
iTrader: 6 / 100%
 

astereo is on a distinguished road

Send a message via AIM to astereo Send a message via Skype™ to astereo

  Old  Wordpress / PHP Help

Hello all,
I'm in the final stages of wrapping up a big theme project for a client, and one of the things they've asked me to integrated is a link cloaker. I found the "Affiliate hide" plugin but I've been tweaking it so it pulls from a specific custom field.

The main function of the plugin is as follows:

PHP Code:
function affiliate_hide() {
global 
$wp_query;

if( isset( 
$wp_query->query_vars['go'] )) {
    
    
$target get_post_meta($wp_query->query_vars['go'], 'url'true);
        if(
$target == '') { 
        
wp_redirect(get_option('siteurl')); exit; // if no blog post redirects to index page.
        
}
    
wp_redirect($target301);
    exit;
    }

The 'url' is referring to the custom field in which the link to be cloaked is found. My problem is that I followed this add meta box tutorial to utilize custom fields in a much nicer interface for my clients clients. This particular tutorials stores everything in an array, so I typically access values like so:

PHP Code:
$my_meta get_post_meta($post->ID,'_my_meta',TRUE);
echo 
$my_meta['link']; 
my problem is being able to grab the 'link' in place of the 'url' in the plugin function. I've tried a wide variety of things but just can't seem to figure it out.

Any help would be appreciated.
Thank you!

02-04-2012, 05:23 PM
#2
Michael C is offline Michael C
Michael C's Avatar
Status: Senior Member
Join date: Jul 2006
Location: Scotland, East Lothian
Expertise:
Software:
 
Posts: 888
iTrader: 4 / 100%
 

Michael C is on a distinguished road

Send a message via MSN to Michael C

  Old

Do you not just change to:
$target = $my_meta['link'];

With the other line above it.

02-04-2012, 07:12 PM
#3
astereo is offline astereo
astereo's Avatar
Status: Member
Join date: Jun 2005
Location: east coast, usa
Expertise: design,development, & WP
Software: Photoshop, Illustrator, WP
 
Posts: 421
iTrader: 6 / 100%
 

astereo is on a distinguished road

Send a message via AIM to astereo Send a message via Skype™ to astereo

  Old

The initial part of the target (get_post_meta($wp_query->query_vars['go']) serves the purpose of grabbing the post id # and clocking the link appropriately.

Process goes like this:

1) user can set the "jump link" from a settings page, ie, domain.com/visit, domain.com/go, etc
2) this plugin is intended to mask the url (originally meant to come from a custom field 'url'), and mask it as domain.com/<user defined link base>/<postid>

I could easily make a custom field called "url" and it would work fine, but because of some custom meta boxes I already have in place for a nicer looking, more descriptive interface, all of this info is already stored within an array.

Reply With Quote
02-04-2012, 07:26 PM
#4
Michael C is offline Michael C
Michael C's Avatar
Status: Senior Member
Join date: Jul 2006
Location: Scotland, East Lothian
Expertise:
Software:
 
Posts: 888
iTrader: 4 / 100%
 

Michael C is on a distinguished road

Send a message via MSN to Michael C

  Old

Isn't information inputted in a meta box also available as a custom-field? At least it is the way I do it. If you show the custom fields you should see the id with value. I don't see whats wrong with:

PHP Code:
function affiliate_hide() { 
global 
$wp_query

 
$my_meta get_post_meta($post->ID,'_my_meta',TRUE);
if( isset( 
$my_meta['link'] )) {  
    
$target $my_meta['link'];   
        if(
$target == '') {  
        
wp_redirect(get_option('siteurl')); exit; // if no blog post redirects to index page. 
        

    
wp_redirect($target301); 
    exit; 
    } 

Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed