Forum Replies Created

  • Sorry, but unfortunately I didn’t. Good luck!

  • Thank you oncecoupled. This drove me crazy as well. The problem does still occur in Pro 5.12. As a tip for others: In the customizer widgets appear, which don’t show up on the frontend. We actually had to delete and then add the widgets again for them to appear on the frontend.

  • Hi,

    are there any news regarding this. I just stumbled upon the same problem on one of our site. If the fields are registered via the backend, the custom values are available on new posts. When registering the field via php, custom values only are available for the posts, there were created on.


  • Thanks John! Why didn’t think of this? It’s straight forward and so much easier to understand then what I did.

  • Okay, here is something I found out, which is working for my use case and might be helpful as a starting point for someone in the future. There might be better and more elegant ways to do this, but at least it does the trick in some cases.

    Background: I use a post_relation field (among other) inside a repeater field and want to query all posts, which do not have a relation to one or more given post ids. As an example: I query posts of a post_type ‘recipe’ and want to get all posts (=recipes) which dont have a relation to some ingredients (‘ingredient’ is a post_type as well). The repeater field is named ‘ingredients’ and the relation field inside the repeater is called ‘ingredient’.

    I build my wp_query step by step: standard query_args, meta_query_args and so on. Then I have an array of unwanted recipes. If this array is set (has values) I build a subquery and simply attach it at the end of the where clause (maybe not the best spot in regards to performance?). All of this happens in a closure (also, maybe not the best way to do this?).

    if ( isset( $without_ingredients ) ) {
    			add_filter ('posts_where', function($where) use ($without_ingredients) {
    				global $wpdb;
    				$sql_in_no_repeater_extension = " AND $wpdb->prefix" . "posts.ID NOT IN (SELECT post_id FROM $wpdb->prefix" . "postmeta WHERE meta_key LIKE 'ingredients_%_ingredient' AND meta_value in (" . implode (',', $without_ingredients). "))";
    				return $where . $sql_in_no_repeater_extension;

    What the simple subquery does, is getting the post id of all posts, having one of the uwanted post (ingredient) ids inside their ‘ingredients’-repeater subfields. Then these ids get removed from the original query.

    So, maybe this helps someone sometime. If anyone has a hint how to do this better, I’d realy appreciate to read them.

  • Thanks John! I’ve seen this hook, but thought it would only work in wp-admin.

Viewing 6 posts - 1 through 6 (of 6 total)