Support » Fixing WordPress » Custom Fileds

  • Hi community,
    I am coding a theme and within that process a problem occured. Therefore I would like to know if/how it is possible to fix it. My problem is related to custom fields.

    I need:
    I need the custom fields organized in pairs. The first part of the pair will be the date and the second part will be the state. State can be 0, 1 or 2 the date is quite simple. The result might be like that:

    post #1 / 1.1.2020/ State: 0
    post #2 / 2.1.2020/ State: 1
    post #3 / 3.1.2020/ State: 1
    post #4 / 3.1.2020/ State: 2
    post #5 / 5.1.2020/ State: 0
    post #6 / 6.1.2020/ State: 2
    post #7 / 7.1.2020/ State: 0

    Then I want to create a loop and ask for displaying a list of all posts in a given period. e.g: list all posts between 3.1.2020 and 5.1.2020 The posts should have different classes according to their state. So the output could look like:

    <div id="post3 class="state1">...</div>
    <div id="post4 class="state2">...</div>
    <div id="post5 class="state0">...</div>

    I suppose it is possible, but I do not know how to group the custom filds in the right way. Maybe somebody could give me a hint. Using a plugin such as ACF is OK, if necesairy.


Viewing 4 replies - 1 through 4 (of 4 total)
  • Please consider that this sort of thing belongs in a plugin, not a theme.
    If the date is different from the publish date, it belongs in its own custom field.
    The state probably would work best as a taxonomy.
    Read up on the WP_Query class for how to request specific data.

    Thread Starter rabox66


    Hi Joy,
    thank you for the answer. Whether it will be stored in a plugin or somewhere else is not the main problem. My main question is: Is it possible to “group” the custom fields. Because I always need a pair of information:

    custom field 1 might be a date,
    custom field q a state (0, 1 or 2)

    custom field 3 might be a date,
    custom field 4 a state (0, 1 or 2)

    custom field 5 might be a date,
    custom field 6 a state (0, 1 or 2)

    So how can I guarantee that field 11 is grouped with field 2, and field 3 is grouped with field 4 … That is my basic-question.

    I read in the documatation of the plugin “Advanced Custom Fields (ACF) that this plugin can group the fields. But I do not know if that means exactly that what I want.

    It is a bit hard to explain what I want. So the first thing should propably be that we make sure to talk about the same thing.

    Moderator bcworkz


    Don’t store two values in one field if you want to query by these values. Otherwise you could store value pairs as an array of values or key => value pairs. But if you do that you cannot use the custom fields meta box because you need to handle the submitted values with your own code that combines values into an array. It’s a lot easier to just use separate fields.

    If you want to query by date meta values, either store the date as a timestamp or in “” format so that ordering and ranges work as expected.

    Thread Starter rabox66


    bcworks thanks. Ah, OK. I overread that you already resolved the problem. I need arrays of fields. ! Thanks! But how do I get them? Is there a plugin that can group fields in arrays?

    • This reply was modified 1 year, 4 months ago by rabox66.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Fileds’ is closed to new replies.