@Poremsky.com

Tips & Tricks for Windows, Office, and Whatever

  • Home
  • Windows
  • Office
  • Web Design
  • WordPress
  • Internet Explorer

Using a WordPress slug and custom field query

Published on August 16, 2012 Last reviewed on May 3, 2017

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.

Custom wordpress fieldsI 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.

Share this:

  • Facebook
  • LinkedIn
  • Twitter
  • Print
Subscribe
Notify of
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Recent Posts

  • Use a JavaScript bookmarklet to open an archive for a webpage
  • How to fix records that are all in one column
  • Change Password or Pin Complexity after removing from Intune
  • Server drafts location is not valid error message
  • What is the Brown File Box Icon on Files in Windows 11?

Recent Comments

  • FUAD on Remove Office Licenses from Windows
  • Brian DuBridge on Add the Recent Items Folder to Windows 10 Quick Access
  • Renee Moodie on Remove Office Licenses from Windows
  • John P on Remove Office Licenses from Windows
  • Puja on Remove Office Licenses from Windows
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

© 2025 · @Poremsky.com

wpDiscuz
Go to mobile version
You are going to send email to

Move Comment