Site icon @Poremsky.com

Using a WordPress slug and custom field query

I wanted change how I publish my newsletters in the EMO archive section at slipstick.com; they are currently in HTML files on the site (copied from the HTML i used for the newsletter, so it was simple to do) but I really wanted them in WordPress and I wanted to link the articles in the newsletter to their article on the site, rather than using the boring plain old HTML as I do now.

I knew I could do it with tags and I didn't mind tagging the articles with issue numbers but I needed an easy way to pull the tagged articles into the page.

I found a function to get the page slug and used the slug in the query in a page template. I added the slug as a tag on articles that were in the newsletter and the new EMO archive pages were ready to go. All that is left to do is to set up the pages and move the content. (The KB article listings are in each page.)

<?php query_posts('tag=' . the_slug() .'&orderby=title&order=asc'); ?>

The result is this layout: Exchange Messaging Outlook (The KB article list is in the page – I rerun the content function so it follows the article excerpts.)

I was pretty happy with it but decided the EMO "portal" page with links to all of the articles published in EMO had to go too (the individual year's index pages have the links). I wanted to use excerpts from several of the most recent issues but needed an easy way to update the tags the query uses. I did not want to tag and untag articles each week. Then it hit me: custom fields.

I created a custom field and assigned the slug/tags to the value, entering them as a comma separated list.

I use get_post_meta to create the query:

<?php query_posts('tag=' . get_post_meta($post->ID, 'emo-archive', true) .'&orderby=title&order=asc'); ?>

Next project: seeing where else I can use custom fields to pull in content and seeing if custom fields can replace widget logic for a few widgets.

Exit mobile version