Coding For Online Success

Issues with CJNiche WordPress Plugin


So I’ve been working with the cjniche plugin. Overall, it’s a pretty good plugin, but I definitely have some issues with it. I noticed that a few of my requests were getting the dreaded PHP warning:

Warning: Invalid argument supplied for foreach() in
plugins/cjniche/cjniche.php on line 79

Want to see if it’s a wide spread problem on the interwebby? Check out this Google search on the topic.

The line number may vary with yours, I added some extra special customizations to the plugin. Googling around on this, I see constant references to this error relating to this plugin. I also see crazy recommendations like deactivating and reactivating the plugin. Reminds me of the ‘did you reboot your computer’ and if the answer it ‘yes’, you follow up with ‘how many times’. Odd how some things just go away. Well, I wasn’t buying it.

It is true if you add a space to the advertiserIds or dork up your CJ Key you’ll get the same error, but I was experiencing intermittent errors. It would work a few of the times, then not work the other times. That would have NOTHING to do with variable values stored in the database. I did some digging (which is hard with this particular plugin since they encode everything.. really?).  I was able to get to the root of the problem.

If you’re getting this error every time, the plugin is not receiving a proper XML response CJ and that is why the foreach is blowing up. Unfortunately, the plugin is not checking for a good product set return from CJ and just explodes. Now, if you’re getting this error some of the times, the problem is very similar. I was able to echo the XML returning during a failure and this is what I saw:

[error-message] =>; The server is currently at
capacity or down for maintenance. Please try again later.

Wow, now that helps shed some light on the problem for sure. Looks like CJ is having problems. This is my biggest irritation dealing with CJ’s datafeed. I’ve mentioned that in the past that it’s just not reliable. This plugin is nice for something quick and if you’re working with small data sets or small merchants, this probably works really well. If you’re dealing with larger product catalogs, the keyword filtering is obviously going to take longer and probably cause issues with many requests. Now this is an assumption. I’m not sure if yesterday and today are the only two days having problems.. who knows. What I wanted to do with this post was shed some light with the PHP error and this plugin. I definitely see mention of it in many places.

I’ve written some error handling in the plugin to catch vs. explode when this occurs, but I might need to work on a caching solution to fall back on a stored data set if it has trouble.


  1. Agreed that CJ’s API is very shaky. Also, compared to Amazon’s and eBay’s APIs, it looks very poor indeed. You get about 10 different data fields, and no advanced searching features whatsoever. Even the CSV files you can order from CJ are richer in data – I am writing an app which uses those at the moment. It’s more reliable too – don’t have to worry about caching in case the server’s down.
    .-= markowe´s last blog ..Quality Click Pricing – evil or good? =-.

  2. I agree markowe about using the CSV instead of the API. I sweat I go back and forth on this. I want the ease and quick implementation of the API, but I like the ability to suck in a datafeed into a local database and reference that instead. I just hate the set up, the fetch, etc. Do you know of any decent WP plugins that can do this? Normally, I roll my CJ sites that use datafeeds, but would like to use WordPress for the ease of crankin’ out sites.

    I just finished tweaking the plugin to cache, so we’ll see how it works. I’ll be doing some real word testing later this afternoon.


  3. CJ WordPress plugin? Who knew. I didn’t. At least, I haven’t reached the point where I can start tapping CJ yet…I’m still working the eBay and AdSense angle, but CJ is on my list.

    Markowe, are you going to sell your code? 😉
    .-= Wayne John´s last blog ..Make Money Online Status Report for December 2009 and the year =-.

  4. You know, I wish I could sit down and actually write something user-friendly and scalable enough to market, but even if I did I just haven’t got the resources to support a paying product. And I can’t really give it away cos I’ll just have zillions of sites with the same footprint as mine! Maybe I’ll release the code I wrote to check for a new feed once every 24 hours, download, rapidly unzip, import etc. Does some of that as shell processes so as to avoid overloading the server, quite happy with it. But then you’ve got to figure out what to do with that data, each CSV has a different data structure etc. so you can’t really write a one-size-fits-all script. If you have any ideas, I’d be happy to hear them!
    .-= markowe´s last blog ..Quality Click Pricing – evil or good? =-.

  5. markowe

    I hear you on all counts. That’s my biggest issue with the CSV route, having to massage the data in every instance. I might play with the idea of PHP CLI script to the import (I already have some code here on the site somewhere), but then write a plugin with shortcode filters in there to craft the query, etc.

    I hear you on the footprint. I try to avoid that as well.

  6. Yes, I am trying to write as much resuable code so that I can flexibly specify what fields are pulled out where, what columns headings go where etc. I can create basic product listings etc. from just about any CSV file with a few judicious changes in a config file. But that would be hard to translate into a user-friendly backend for a less savvy user. And there are always things that have to be custom-written – custom joins, auxiliary tables to hold things like categories. Musn’t get started on product category hierarchies – every advertiser has a different implementation, but most boil down to having to explode one field into lots of little ones, by whatever separator they happen to have used, which for say 50,000 products is just too heavy on the server – still trying to figure out how to make this easy on the server AND easily customisable… The problems go on… What happens if you want to do some product comparison – that’s all this multiplied to the nth power because you’ve got to harmonise the data somehow. No wonder people pay to use aggregated feeds – someone else has done all the work… On the upside, once you have succeeded, you probably have a set of data that is unlike anyone else’s and thus avoids footprint problems.

    By the way, LOAD DATA INFILE is an absolute godsend for large imports! Not so good if you want to aggregate data though…
    .-= markowe´s last blog ..Quality Click Pricing – evil or good? =-.

  7. To date I have not had an issue with the plugin. The only thing that I would like to see is products side by side instead of one after each other down the page.
    .-= Paul´s last undefined ..Response cached until Fri 23 @ 17:18 GMT (Refreshes in 0.60 Hours) =-.

Leave a Reply

Required fields are marked *.

CommentLuv badge

This site uses Akismet to reduce spam. Learn how your comment data is processed.