• Resolved vesnama

    (@vesnama)


    Hello,

    I’m trying to customize options for admin post edit for Relationship field.

    Here is what I haven’t found solution for in forums nor in documentation:

      Display field in selection list: can I have 2 fields displayed in drop down list? I tried this and it doesn’t work: {@post_author}: {@post_title}
      Customized WHERE: can I have current user filtered posts? I tried this but it doesn’t work: post_author={@post_author}
      How can I define GROUP BY to sort list items by usernames like this for example:

      John
      – post title A
      – post title X
      James
      – post title Y
      – post title Z

      I tried this but it doesn’t work: post_author.name

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @vesnama

    Both your requests aren’t features of Pods at the moment.
    You can always create a feature request on GitHub but this will require a quite large refactor of the core system so it won’t be possible to add this soon.

    Cheers, Jory

    Thread Starter vesnama

    (@vesnama)

    Hi @keraweb,

    Which 2?

    I asked for 3 relationship customizations:

    • Selection list display data
    • WHERE options
    • GROUP BY options
    • Hope at least one has solution? ??

    Plugin Author Jory Hogeveen

    (@keraweb)

    Display field in selection list: can I have 2 fields displayed in drop down list? I tried this and it doesn’t work: {@post_author}: {@post_title}

    Nope! You can only query for one field.

    Customized WHERE: can I have current user filtered posts? I tried this but it doesn’t work: post_author={@post_author}

    See here: https://docs.pods.io/displaying-pods/magic-tags/special-magic-tags/
    {@user.ID}

    How can I define GROUP BY to sort list items by usernames like this for example:

    Nope, this is SQL related, not UI.
    https://www.w3schools.com/sql/sql_groupby.asp

    Cheers, Jory

    Thread Starter vesnama

    (@vesnama)

    For WHERE tag suggested {@user.id} doesn’t help.

    I tried this:
    category.slug = “radovi” OR category.slug = “works” AND post.post_author={@user.id}

    But the page breaks.
    I tried instead of post.post_author also id, user.id, post_author but they all either break the page or give me results from all authors.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Thread Starter vesnama

    (@vesnama)

    I tried these and one Breaks the page, and other shows posts by all authors:

    t.post_author={@post.post_author}
    t.post_author={@user.id}

    What am I missing?
    I see now i didn’t give Full info In beginning question. I apologize ??

    This is custom post type “autori” with 2 relationship fields:

      Extended user pod
      Extended post pod

    In the dropdown for choosing related posts i wish to be offered only posts by user/autor I chose In user related field. So it is some kind of conditional from one field to another?

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @vesnama

    Ah, since you showed a shortcode I assumed this was related to the front-end.
    The field options for relationships are somewhat limited here. I believe magic tags are not fully supported for example.

    You might try the following:

    ( category.slug = "radovi" OR category.slug = "works" ) AND t.post_author={@user.id}

    Though I’m not sure if global magic tags are supported here.
    You can try to add ?pods_debug_sql=1 or ?pods_debug_sql_all=1 to your URL to see what SQL is being generated.

    If you really want full control on this are you should use PHP hooks and return your own data:
    Function: https://github.com/pods-framework/pods/blob/2.8.10/classes/fields/pick.php#L2192
    Hook: https://github.com/pods-framework/pods/blob/2.8.10/classes/fields/pick.php#L2244

    Setting those params in PHP will give you more options, however this is considered advanced usage and experience with PHP and SQL is required!

    Cheers, Jory

    Thread Starter vesnama

    (@vesnama)

    Suggested
    t.post_author={@user.id}
    Doesn’t have an effect, posts by all authors still being listed.

    I’m not into developing my own function, not that skilled unfortunately.

    Plugin Author Jory Hogeveen

    (@keraweb)

    You can try to add ?pods_debug_sql=1 or ?pods_debug_sql_all=1 to your URL to see what SQL is being generated.

    What is the SQL being created?

    Thread Starter vesnama

    (@vesnama)

    Tnx, i wasnt aware of this easy Way to check Pods sql query ??

    So, what I see from it is that t.post_author={@user.id} asks the sql query for the value of the currently logged in user editing the pod extending users, not the actual extended user I’m editing. So instead of {user.id} i would need the ID of the author of this extended user post. I tried t.post_author={@post_author.id} and t.post_author={@post_author} but it breaks sql checking.

                    SELECT
                    
                    DISTINCT
                    <code>t</code>.<code>ID</code>, <code>t</code>.<code>post_title</code>, <code>t</code>.<code>post_type</code>, <code>t</code>.<code>menu_order</code>, <code>t</code>.<code>post_date</code>
                    FROM <code>wp_posts</code> AS <code>t</code>
                    
    					LEFT JOIN <code>wp_term_relationships</code> AS <code>rel_category</code> ON
    						<code>rel_category</code>.<code>object_id</code> = <code>t</code>.<code>ID</code>
    
    					LEFT JOIN <code>wp_term_taxonomy</code> AS <code>rel_tt_category</code> ON
    						<code>rel_tt_category</code>.<code>taxonomy</code> = 'category'
    						AND <code>rel_tt_category</code>.<code>term_taxonomy_id</code> = <code>rel_category</code>.<code>term_taxonomy_id</code>
    
    					LEFT JOIN <code>wp_terms</code> AS <code>category</code> ON
    						<code>category</code>.<code>term_id</code> = <code>rel_tt_category</code>.<code>term_id</code>
    				
                    
    						LEFT JOIN <code>wp_term_relationships</code> AS <code>polylang_languages</code>
    							ON <code>polylang_languages</code>.<code>object_id</code> = <code>t</code>.<code>ID</code>
    								AND <code>polylang_languages</code>.<code>term_taxonomy_id</code> = 3
    					
                    WHERE ( ( <code>category</code>.<code>slug</code> = "radovi" OR <code>category</code>.<code>slug</code> = "works" AND t.post_author=1 ) AND ( <code>t</code>.<code>post_type</code> = 'post' ) AND ( <code>polylang_languages</code>.<code>object_id</code> IS NOT NULL ) AND ( <code>t</code>.<code>post_status</code> IN ( 'publish' ) ) )
                    
                    
                    ORDER BY t.post_date, <code>t</code>.<code>menu_order</code>, <code>t</code>.<code>post_title</code>, <code>t</code>.<code>post_date</code>
                    
                

    What I did find in the very beginning in sql checking is the ID i need, but how to put it in magic tags. Number 2 here is the value i would need since this is the user ID of extended user post author I’m editing:

    SELECT
                    
                    DISTINCT
                    <code>t</code>.<code>ID</code> AS <code>pod_item_id</code>
                    FROM <code>wp_users</code> AS <code>t</code>
                    
                    WHERE ( <code>t</code>.<code>ID</code> = 2 )
                    
                    
    Thread Starter vesnama

    (@vesnama)

    Sorry, no preview option for msg so I didn’t figure out code tag would be killed by ”’ from my sql check…

    Here is again the beginning of sql check which has the value i need later in magic tags?

    SELECT
                    
                    DISTINCT
                    <code>t</code>.<code>ID</code> AS <code>pod_item_id</code>
                    FROM <code>wp_users</code> AS <code>t</code>
                    
                    WHERE ( <code>t</code>.<code>ID</code> = 2 )
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @vesnama

    Ah now I understand what you are trying to do.

    {@user.id} refers to the current user (logged in user).

    I honestly doubt what you are trying to do is even possible within these options (without PHP) but you could try the following:

    ( category.slug = "radovi" OR category.slug = "works" ) AND t.post_author={@post_author}

    This COULD work if the magic tag would refer to the current (being edited) object, but I’m honestly not sure it is..

    Cheers, Jory

    Thread Starter vesnama

    (@vesnama)

    I tried this, it breaks the web totally disolaying wmlry white edit page.

    Thread Starter vesnama

    (@vesnama)

    Sorry, typo.
    IT displays empty white edit page.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Please enable debug to show the error:

    Debugging in WordPress

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Relationship options: where, group by, display, order by’ is closed to new replies.