Advertisement:

Author Topic: [SOLVED] get item url by item id  (Read 3707 times)

DrLightman

  • Newbie
  • *
  • Posts: 36
[SOLVED] get item url by item id
« on: May 14, 2014, 01:13:27 pm »
This seems pretty basic, but I can't find it anywhere in the source, still looking.

I need the Wordpress equivalent of get_permalink($id), is there anything similar? A function to retrive the full friendly url to an item given the item id.

Thank you
« Last Edit: May 17, 2014, 06:58:00 pm by DrLightman »

DrLightman

  • Newbie
  • *
  • Posts: 36
Re: get item url by item id
« Reply #1 on: May 14, 2014, 01:17:02 pm »
Ok as always happens I find the thing after I open a thread. I found something similar: osc_item_url_from_item, still not by id but it's something at least.

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: get item url by item id
« Reply #2 on: May 14, 2014, 01:42:07 pm »
Hi,

I assume osc_item_url() isn't working for you where you want this? If so, please elaborate.

Regards

DrLightman

  • Newbie
  • *
  • Posts: 36
Re: get item url by item id
« Reply #3 on: May 16, 2014, 12:59:34 pm »
osc_item_url() would be perfect if it would accept an [optional] $id argument, but it only works for the currently selected item in a view template file. Instead I needed that to build a redirect table map to migrate an old site to the new site, in an external script.

old url --- redirect 301 ---> new url

To do this I cycled old ads based on another script and for each of them given the id of the new corresponding osclass item I needed to generate the new working url.

Another use was to do a random.php file in the osc root directory that would pick a random item and redirect to the item, per request of a client. Just for info I post how it came out (it works):

/random.php - if called http://example.org/random.php it redirects to a random item
Code: [Select]
<?php
define
('CLI'false);
require_once 
dirname__FILE__ ) . '/oc-load.php';
ob_end_clean( );

$link false;

$s = new Search;
$s->addItemConditions('1 = 1');
//$s->order('RAND()');
$s->order('','random');
$s->limit('0','1');
$items $s->doSearch();

if( 
$items ) {
$link osc_item_url_from_item$items[0] );
}

if( 
$link ) {
header'Location: ' $link );
exit;
} else {
echo 'Server Error';
exit;
}
?>

teseo

  • Hero Member
  • *****
  • Posts: 6169
Re: get item url by item id
« Reply #4 on: May 16, 2014, 01:40:41 pm »
Code: [Select]
View::newInstance()->_exportVariableToView('item', Item::newInstance()->findByPrimaryKey($id));
Now you may use osc_item_url().

Regards
« Last Edit: May 16, 2014, 01:42:13 pm by teseo »

DrLightman

  • Newbie
  • *
  • Posts: 36
Re: get item url by item id
« Reply #5 on: May 16, 2014, 01:48:01 pm »
Thanks!