• Resolved gearheaddeals

    (@ghdwpadmin11)


    I have tried searching and reading a few threads but this level of code is above my current abilities.

    I am trying to setup a category template that will sort posts based on a new variable I within a New Post body.
    The variable is the date that the item sale ends in a format similar to MM-DD-YYYY so when sorted ascending should put the earliest expiration date first.

    Pseudocode would be something like:
    ——————–

    Add New Post–>
    Post content……
    Expires On: [create variable “expiration_date” = input(MM-DD-YYYY)]
    display “expiration_date”
    countdown timer plugin (pass in variable “expiration_date” for use by plugin)

    ——————-

    category-expire.php

    sort by “expiration_date” order=ASC

    ——————-

    I will be able to post the current template code later from home.

    Can anyone help with this? It seems simple enough, but I am just lost right now.

    Thank you very much.

Viewing 10 replies - 16 through 25 (of 25 total)
  • Thread Starter gearheaddeals

    (@ghdwpadmin11)

    when I insert your snippet, it just shows up on the top of the category page above the first post. is there another location I should try?

    Try <?php query_posts( $query_string . '&meta_key=expiration_date&orderby=meta_value_num');?> ??

    Thread Starter gearheaddeals

    (@ghdwpadmin11)

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

    So that’s what I have, and this is what I get

    https://www.gearheaddeals.com/category/expiring/

    The exp. date shown there is unrelated to the meta_key. It is just written in the post, but the meta keys match that date and you can see that it is not in order.

    I also changed the meta_key variable name to “expiration” for simplicity

    Thread Starter gearheaddeals

    (@ghdwpadmin11)

    currently the key is like this 2011-10-05 and the plugin “more fields” is set to take in a date of that format.

    Thread Starter gearheaddeals

    (@ghdwpadmin11)

    Does anyone have an idea on what I’m doing wrong here?

    Thread Starter gearheaddeals

    (@ghdwpadmin11)

    I tried changing the field to take the number date in the form
    20111005
    20111006

    and sort ascending but it still isnt working.

    I put this before the loop:

    <?php if (is_category('category-expiring')):
    		    query_posts( $query_string . '&meta_key=expiration&orderby=meta_value_num&order=ASC');
    		    endif; ?>

    still nothing.

    Thread Starter gearheaddeals

    (@ghdwpadmin11)

    actually replaced the query with some text “test” to make sure it would put “test” above the posts on that category page and got this:

    Parse error: syntax error, unexpected T_ENDIF in /home/foxst2/public_html/filepath…/archive.php on line 27

    But putting the word “test” outside the IF and before the loop, i see what I expected.

    Thread Starter gearheaddeals

    (@ghdwpadmin11)

    ok somehow I got it working. I copied my entire code from my regular template into my new “category-expiring.php” template, then added the code you had given before

    <?php query_posts( $query_string . '&meta_key=expiration_date&orderby=meta_value_num');?>

    and somehow it worked this time.

    thank you very much.

    Thread Starter gearheaddeals

    (@ghdwpadmin11)

    now I would like to use an IF statement so in conjunction with the sorting it would be something like:

    IF expiration_date – todays_date > 0
    display post
    ELSE
    END

    so that expired deals would not be posted, even though their checkbox for this category is checked

    any ideas on this one?

    Thread Starter gearheaddeals

    (@ghdwpadmin11)

    anyone have any help on adding the IF statement just above this post?

Viewing 10 replies - 16 through 25 (of 25 total)
  • The topic ‘Create New Variable In Post And Sort Category Template By That Variable’ is closed to new replies.