• Here is the site I am working with for reference: http://cedarhillchamber.org/businesses/business-directory/

    This list is a list of categories that have members within them. There are three types of members, only two of which are relevant to what I’m trying to do: Member and Premium Member. When you click a category the members that fit inside this category are listed with links to their individual posts.

    I need to find the premium members at the top of their respective category, and the rest alphabetically below that.

    I have only the smallest inkling of how something like this can be done, so any direction would be extremely useful.

    Thanks.

Viewing 15 replies - 1 through 15 (of 23 total)
  • I believe that what you want can be handled by using filters to alter your query. Can you post a few lines of code that show the query you are currently using?

    How do you set the option for member type, is it a custom plugin or a field on the user?

    You would need to create an array of user_ids in order, and then loop filtering the posts by post_user and category, but it will depend on where the Member and Premium member are set for you to load the array?

    David

    Thread Starter dginther

    (@dginther)

    Hey, guys.

    Thanks for the responses. Right now here is all that is on the page:

    <?php if (have_posts()) : while (have_posts()) : the_post(); // the loop ?>
    <!–post title as a link–>
    <h3 id=”post-<?php the_ID(); ?>”>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></h3>

    So when you go to the business directory you click a category (i.e. Accounting), and when that page loads it is a listing of all the posts that fit under that category, so it is not using their membership status (two other category types) to determine how things get listed.

    To answer your question DR;

    The member type is another category that is clicked when the entry for a business is created. So, for example, when an entry is created for Joe’s Rib Shack it is put under the categories of “Restaurants” “Member” and “Premium Member” if it applies.

    It is not that simple, have a look at this topic from the other day, not the same but close.

    You would need two queries filtering the posts using a WP_Query, run premium first and then members.

    $query = new WP_Query( array( 'category__and' => array( 2, 6 ) ) );
    $query = new WP_Query( array( 'category__and' => array( 'restaurants', 'premium-member' ) ) );
    $query = new WP_Query( array( 'category__and' => array( 'restaurants', 'member' ) ) );

    HTH

    david

    Thread Starter dginther

    (@dginther)

    I knew it wasn’t going to be something so simple. The site was built without taking this feature into consideration.

    Thanks for the suggestion, I figured I was going to have to do two separate queries, but had no idea how to get started.

    Thread Starter dginther

    (@dginther)

    Taking a look at what you have there, is it possible to replace ‘restaurants’ with page id or something like that, so that field can be filled in automatically depending on the category some one clicks?

    To do it in one, consider using a custom field ‘member’ and WP_Query with post meta fields, then you can sort by them, but not categories.

    $query = new WP_Query( array ( 'orderby' => 'meta_value', 'meta_key' => 'member' ) );

    You could write a function for the save post that will set the metadata based on the post categories, when saving if the post has the category slug premium-member then set the meta to 2 else 1

    HTH

    David

    Thread Starter dginther

    (@dginther)

    That would be a good idea, had that been implemented when the site was built, but there is more throughout the site dependent on the member categories than just this list, and there are already 400 entries that would have to be adjusted to make that work.

    Post the directory code up in http://pastebin.com it may make it easier.

    David

    Thread Starter dginther

    (@dginther)

    Pardon my ignorance, but I don’t really know what you need.

    The page code that dispalys the list, from where you posted the code above, also do you have a local copy of the website for testing code?

    David

    Thread Starter dginther

    (@dginther)

    Here are my pastebins:

    http://pastebin.com/qwVyJk4b – This is the page that calls in all of the posts for the category. (as seen here: http://cedarhillchamber.org/category/business-directory/advertising-marketing/ )

    http://pastebin.com/XbNMJA40 – This is the page that lists all the categories as a directory (as seen here: http://cedarhillchamber.org/businesses/business-directory/)

    And no, I do not have a local version of this to work with.

    Ok,
    To test you really need a local copy of your website, a bad line of code can lock you out of the admin area, and make a bad experience for visitors.

    A bad plugin or upgrade can also wreck a WordPress website, with a local copy you will have a chance to test plugins and upgrades.

    Windows:
    Look at WAMPP, or there is Instant WordPress a nice free little application that requires no changes to registry etc:, it also has a paid document that might be of use.

    For the MAC there is a all in one package called LAMPP.

    Once you have a local install, you can export your content from Admin > Tools and import it to a test database, then changing code will be easy, if there is a fatal php error, it is easy to reverse the change.

    I would think that a couple of functions one to update the historic posts adding a meta value, and another that will update when a post is saved would work, and a sort on the metadata.

    I will have a play with that tomorrow, with a twenty eleven theme and a test database to see what I can work out.

    HTH

    David

    I think this will do what you want. Paste the code below just before this line in the file that shows the category:

    <?php if (have_posts()) : while (have_posts()) : the_post(); // the loop ?>

    This is the code to paste in (Be sure to put in your own $premium_id number!):

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thread Starter dginther

    (@dginther)

    Wow, it definitely looks like you put a lot of work into that. Can you give me a brief summary of what is happening before I place this code?

Viewing 15 replies - 1 through 15 (of 23 total)

The topic ‘Listing posts with multiple categories’ is closed to new replies.