Custom Post Order Query Loop / Metabox

Hi,
I’ve read the other posts about ordering a the display order of a query loop, but nothing is working for me.

I have added a metabox numeric field to a custom post type, simply want to add a numerical ordering to each post … 1,2,3

in the query loop,

  • order: by : meta numeric value
  • order meta key: string that I added to the meta query below

Added a meta query

  • gave the meta key a string name
  • meta value: associated metabox numeric value field

Nothing displays.
If I remove the meta value string above and in the meta query below, it displays them all again, but not in the correct order.

Anyone have any ideas how to fix this?

Hi

I have a query that sorts my custom posts via a custom field called “nr” and it works without problems. I enter the numbers in that field as 01, 02, 03, … 10,11,12,… I have not more than 99 posts. If it would be more, I would enter the numbers as 001, 002, 003, etc.

I defined the custom field “nr” as a text field in acf:

and in the query I use Meta numeric field as the sorting order:

I don’t know why it works when the field is a text field and the query setting is a Meta numeric field, but who cares as long as it works…

Try it.

Cheers and good luck

Patric

Hi Patric,
Yep, you’re right. Having the following worked like you said:

  • a text field in metabox custom fields
  • using it’s ID in the Order meta key
  • setting it to meta numeric

I also did the 01, 02, thing. Don’t know if it makes a difference but I didn’t mess around with it due to time. Figured I would just copy what works.

Thanks for the recommendations!

1 Like

Hi

because the metabox custom field is defined as a text field, if we don’t use 01, 02, … format, I think it would not work with 10, 20, …, the order would be … 1, 10, 2, 20, 3, 30, etc.

Cheers

Patric

I used ACF but did just that yesterday.

My CPT has a numeric field “testimonial_order”. Then in the query ordering I’ve got it set based on numeric meta value named “testimonial_order” and it works.

And in my opinion, sorting by text field that behaves like numbering while remembering to add 0 as prefix for 1-9 is a weird approach unless you use this field somewhere else and it must be displayed as “01”.

@lynxm it would be best to share a screenshot or screen recording that shows all the settings :slight_smile:.

1 Like

Yeah, I don’t mind in my case as I want to have the 0x format in the block where I have a 2-digit number anyway.

number2

number

I never spent the time to investigate why it didn’t work as a numeric field.

Cheers

Patric

:blush: You’re right.
Here’s your moment of zen.

Agreed on the other comments that text / prepend zeros is a strange implementation. Understand Patric’s rationale though.

1 Like

Yeah, I do agree that Patrick’s case is justified that’s why I wrote “unless you use this field somewhere else and it must be displayed as “01”.” :upside_down_face:


Back to your settings, if I were you I’d share:

  1. Bricks version together with plugins used for what you’re trying to achive
  2. Where is the query used (on page, post, CPT, archive, etc.)
  3. If the field is part of a simple group of fields, repeater or flexible content.
  4. Field settings (type, name, important settings like output format if applies etc.)
  5. Elements structure in the builder
  6. Settings of the query loop in the left pane while stretching it so everything is clearly visible there

Generally speaking it’s always better to add too much information on your setup than too little.

I’d like to stress again that I use ACF and never used MB, so this could be a bug with Metabox in Bricks. As far as I can tell @Patric uses ACF as well.


Going step by step with my setup

Bricks: 1.7.3 (current stable)
ACF: 6.2 (current stable, free)

I use a simple group of fields attached to a CPT named “Referencje” (basicaly testimonials). The field used for ordering is of “Number” type, field name is “testimonial_order”. Other settings tabs like validation shouldn’t matter.

Then on a new page I create a brand new structure using only bricks native elements. Please remember that we set query loop on the element that is meant to be multiplied not on the container (like in Oxygen builder). You can see it as an infinity sign right from Block element in the structure.

obraz

Everything comes “as is” with default settings. The only change I made was to add dynamic field “testimonial_order” as content of the Basic Text. This is done by placeing {acf_testimonial_order} when using ACF, but should be {mb_testimonial_order} if I used Metabox.

This should be changed depending on the source of this dynamic data. Please refer to: Dynamic Data – Bricks Academy. Be especially careful when using repeaters and flexible content or other non-basic setups of fields.

obraz

The query loop set on the Block element looks like this. Important not is to use “testimonial_order” as Order meta key and not “acf_testimonial_order”

Which gives this output on frontend (also visible in the editor)

obraz

This is the DOM structure produced (ommiting stuff before and after <main></main> like header and footer).

obraz

This should give you a CPT query ordered by ACF Number field.


@lynxm reading your post again it seems that you not only set the “order by” but also “meta query” down below in settings. So could you show a screenshots of:

  1. Structure panel
  2. All query settings (can be 2+ separate screenshots) that shows element name (like Block) on top together with “order by” and meta query below. Perfect if you could stretch the panel a bit so everything can be read in full.

It seems that people report some problems with using Metabox fields in Bricks, like here.

1 Like

Interesting. I have just tried to recreate this using 1.8bete2 and ACPT for the CPT stuff.

If I enter a value for the Order meta key then my loop displays nothing.
If I leave out the Order meta key then it displays the loop with the numeric field values but it is sorted on creation time.

I suspect that both ACPT and Metabox have an integration issue. I’ll follow up with ACPT.

If I have some spare time I can test ACPT PRO. For now you could open a separate issue as this one’s title states “Metabox”. If you do so remember to tag Mauro Cassani because he is active in this forum.

Thanks. Already raised it with Mauro.

Hi all,
Sorry for not being complete.
Versions: Bricks 1.7.3 | Meta Box 5.6.18 and Meta Box AIO 1.20.3

This is the field (that now works) in MB.

what didn’t work was when I had a field defined as an html5 number.
image

When I referred to the html5 number, I used the ID, not {mb_ID} (though I tried that too and it also didn’t work)

The html structure is very simple
image

@Matiasko - You’re right that when i was trying to make it work, I did experiment with putting the ID in the meta query, but that is no longer the case.

The query is simple now


image

To be clear, this config is working for me now. Thanks for the great discussion on this topic!

1 Like

Interesting update: I made a new custom field group in Metabox. Within, I used the “group” functionality, and added an orderby text field

image

No matter what combination of strings for the order meta key , I couldn’t get the above approach to work. for example, I added the id of the group followed by underscore and then id of the text field and nothing. Also tried the bull mb_groupId_fieldID and nothing.

In the end I fell back on not putting the order by field within a metabox layout group. When it’s top level, it works just fine as described above