Item Filter

The item filter is called every time an item is loaded from the blog’s database and before the index is either sorted or displayed.  Using this filter allows you to affect the content of each item in the index and the order in which they are sorted.

To add a filter for all indexes in your blog use the following code:

add_filter('azindex_item', 'my_item_filter');

Then add the item filter function with the name you specified:

function my_item_filter($item) {
    /* My item modifying code here */
    return $item;
}

The $item parameter is an associative array containing all the information about the item being loaded into the index.  It has the following keys names:

Key Name Description
id Post id - the id of the post linked to by this item (cannot be modified)
head The item’s heading string, as it will be displayed in the index
subhead The item’s subheading string, as it will be displayed in the index
desc The item’s description string, as it will be displayed in the index
sort-head The item’s sorted heading string – used only when sorting the index
sort-subhead The item’s sorted subheading string – used only when sorting the index
sort-desc The item’s sorted description string – used only when sorting the index
key Category/tag id of the item – only if category/tag is selected as the heading (cannot be modified)

There are two copies of the heading, subheading, and description strings in the item array because you may not always want to use the same strings when sorting the index that you want displayed in the index.  One common example is where you have some items with headings in quotes (e.g. “Red Dwarf”).  This may be what you want to see in the index, but you also want it to appear in the R section of the index (e.g. between Really Fine Wines and Referees—the Most Thankless of Jobs?) and the quotation mark at the beginning of the heading would cause it to be sorted into completely the wrong place.

By turning on the “Ignore specified characters…” option in the index settings, you would see one of the heading strings has the leading quote removed, allowing the item to be sorted in the corrected order in the index.

So, if you just want to affect where an item will appear in the index, use the sort-head, sort-subhead, and sort-desc values, but if you want to modify the content of the item as it appears on the index page then use the head, subhead, and desc values.

The id value is the post id, and is provided so you can access other information about the item.  For example, if you want to display the tags or categories the post has, you can use the post id to access this information and put it in the description field.  (Note: you will have to know something about the WordPress PHP functions to do something like this.)  Changing the value of id in the filter has no effect.

Finally, the key value is only used by indexes that have either tags or categories as the headings. When that is the case, there may be more than one item in the index for a single post (i.e. one for every tag/category the post has), and the key value is used to distinguish which tag/category the item is for.  For indexes with tag headings, it is the tag id, and for indexes with category headings it is the category id.  Changing the value of key in the filter has no effect.

More Item Filter Parameters

If you only want to use the item filter with one specific index, you need to know the id of the index your filter function is being called for.  You can do this by specifying that you want your filter to receive all the available parameters, which is 2:

add_filter('azindex_item', 'my_item_filter', 10, 2);

Note: the third parameter in the add_filter() call, 10, is the default filter priority, and must be present so you can specify the number of parameters you want to be passed to your filter.

Now you can modify the filter function to receive the index id, so you can add a test in your code to see if you need to filter this item.

function my_item_filter($item, $idindex) {
    /* My item modifying code here */
    return $item;
}

Note: in future versions for AZIndex, $idindex may be a string, as well as a number.

Other Notes about the Item Filter

There are some other things to be aware of when you are using an item filter:

  • The item filter is called after AZIndex has modified the item strings according to the options selected in the settings page.  So, for example, if the “Ignore specified characters…” option is set, the sort- fields will already have those ignored characters removed from the front of the string.
  • If you are changing the sort- values, make sure you remove all white-space from the beginning of the strings, otherwise your items will appear in the wrong place in the index.
  • All strings passed into the filter use the UTF-8 encoding, where some characters (like those unique to certain languages) are more than one byte long.  If you are going to manipulate text that contains these multi-byte characters, you should use the PHP multi-byte stringlibrary functions to do so.
  • Before the index is sorted, all item filters will be called for every item in the index.  So, if you are using an item filter with large indexes, make sure it doesn’t take a very long time to execute (e.g. don’t make an http request to another website!) or you may find the index sort timing out.
  • Whenever you add an item filter, or change your item filter code, you may have to clear the index cache (from the index management admin page) before you see the changes in the index.  It’s usually a good idea to turn off caching for the index (in the advanced options) while you are developing an item filter.
  • You may find your item filter function being called at times when you least expect it.  This is because when a post in your blog is changed in some way, AZIndex checks to see if the change affected its position in the index.  For example, if you edit the title of a post then, when you save it, the plugin loads the item(s) for that post and the items before and after it in the index, and performs a mini-sort on them.  If the sorted order has been changed by your edit, then AZIndex knows that next time the index is loaded, it will have to re-sort the index.  In fact, your item filter will be called whenever you save a post, as well as when you add a custom field, a tag or a category to a post, and possibly at other times too.
  • Other keys may be added to the $items array in future releases, so the number of keys and their order may change over time.
  • This filter replaces the old azindex_heading filter.  You can access the same data provided with that filter by using the $item['head'] or $item['sub-head'] value.

No comments yet to

  • Thank you very much for your site. It is very important to me. Thank you.

  • Hi there, I discovered your blog via Google even as looking for a related topic, your web site got here up, it looks great. I’ve bookmarked it in my google bookmarks.

  • betting bonus at bettingbonuses.biz

  • Hey i think your blog is fantastic! I found it on Google. I think i will come back one day soon.

  • What’s Going down i’m new to this, I stumbled upon this I have discovered It positively helpful and it has aided me out loads. I hope to give a contribution & help other users like its helped me. Great job.

  • I’m right there with you, although I would read anything she writes, the cover is definitely intruiging!

  • You know that anything goes once you pick up a work by the zany and terrific Kurt Vonnegut. The man knows how to dish up satire like none other. He’ll spew out his complaints about the government, the world, people, etc., and instead of making it sound like a bunch of inane ranting he uses all of that to create a crazy world filled with outrageous characters and situations. “Breakfast of Champions” is an off-the-wall novel that is about 300 pages of pure hilarity and comedic chaos. Some of the most outrageous characters lie within this masterpiece.Listen: This story revolves mainly around two characters. There’s Kilgore Trout who is an aging and bitter sci-fi writer that nobody has ever heard of (except for one person). His stories have only appeared in very adult magazines. So naturally, he has “doodley-squat” to show for it. The other person that this story is about is a car dealer by the name of Dwayne Hoover, a man that everyone in town considers a “fabulously well-to-do” person. Dwayne is losing his mind and is ever so gracefully slipping into the cozy and wonderful world of insanity. What pushes him over the edge will take place when the two meet and Hoover takes one of Trout’s literary works as reality. The results are unforgettable and hilariously disturbing in this dark and offbeat tale of the flawed human beings who are destroying Mother Earth.

  • Wow good info, thank you. This is what i looking for.

  • More like: The cost of implementing “”"proper”"” security against unmitigated and unreasonable to expect attacks outweigh the benefits, when out contacts will indemnify us anyway. You know why they don’t bother? One, they expect that a person won’t be able to access the equipment without being caught, or won’t risk breaking and entering or other criminal charges to get at best, free laundry. Minimal payout = less incentive to attack, less reason to care.

  • Interesting….
    How did you get the image inside the QR?
    This is all new to me, so I have been googling and reading up as much as possible…

  • Howdy. Very cool website!! Guy .. Beautiful .. Wonderful .. I’ll bookmark your site and take the feeds also…I’m happy to locate numerous helpful info here within the post. Thank you for sharing.

  • I’ve been exploring for a little bit for any high quality articles or blog posts in this sort of space . Exploring in Yahoo I at last stumbled upon this website. Reading this info So i am satisfied to exhibit that I’ve an incredibly good uncanny feeling I found out exactly what I needed. I so much unquestionably will make certain to do not disregard this website and give it a glance regularly.

  • I was just looking for this info for a while. After 6 hours of continuous Googleing, finally I got it in your site. I wonder what’s the lack of Google strategy that do not rank this kind of informative web sites in top of the list. Generally the top web sites are full of garbage.

  • I want to display list of post in category page using AZindex. So I’ve created a category template. Now I need help to display posts list by category there. For instance, when I’ll go to domain.com/category/health, the page should display only post list from health category using azindex. Is it possible? I need your help.

  • I’ve recently started a web site, the info you offer on this site has helped me greatly. Thanks for all of your time & work.

  • I am love this . but can u tell me how to remove points front of the main latter …. Plz visit this link http://www.hostmp4.com/all-movies or tell me how i do that…

  • I’d should verify with you here. Which is not one thing I often do! I enjoy studying a submit that will make individuals think. Also, thanks for allowing me to remark!

  • Excellent read, I just passed this onto a colleague who was doing some research on that. And he just bought me lunch since I found it for him smile Therefore let me rephrase that: Thank you for lunch!

  • It’s actually a nice and helpful piece of information. I am glad that you just shared this helpful information with us. Please stay us informed like this. Thank you for sharing.

  • Browse all brands of best vacuum cleaner today.