[wp-hackers] best route for adding links?

fris fris at fris.net
Sat Jan 21 21:40:14 UTC 2012


I ended up going with wp_list_pluck

function link_exists( $link ) {
        return (in_array($link, wp_list_pluck(get_bookmarks(array('category' => 2)),'link_url')));
}


-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Andy Charrington-Wilden
Sent: Saturday, January 21, 2012 4:22 PM
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] best route for adding links?

Surely getting all links in the db once, sticking them in an array and checking if !in_array would be quicker? If a link is to be added (ie it's not in the array) rather than querying the db again for the next one just add it to the array and do the check on the next one in the csv. In fact you could just add the links that are not already present to another array and then run one insert query built from that array. Only two database interactions for the whole thing. That's what I'd do anyway. 

Sent from my iPhone

On 21 Jan 2012, at 19:35, Daniel Dvorkin <elrabino at gmail.com> wrote:

> You can use get_bookmarks (
> http://codex.wordpress.org/Function_Reference/get_bookmarks ) 
> searching for that URL. Import only if it returns empty. Not very fast, though.
> 
> 
> 
> 
> ---------------------
> Daniel Dvorkin
> Móvil: +54 (0261) 15-315-2244
> Skype: mzaweb
> http://mzaweb.com
> 
> 
> 
> 
> On Thu, Jan 19, 2012 at 3:15 PM, fris <fris at fris.net> wrote:
> 
>> What would be the best way to avoid adding duplicate links.
>> 
>> Im creating a csv link importer, and using wp_insert_link() , but 
>> currently its adding the link even if one exists with the same url.
>> 
>> 
>> 
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list