• Resolved rico34

    (@rico34)


    Hi,

    my WordPress version: 6.5.2
    my Pods version: 3.2.1

    I have set up a pods template for a pods custom post type, created a new page where I place a pods-items-list block. I chose the ‘POD-NAME’ and ‘TEMPLATE’ and my expected content shows up.
    But as soon as I type something in the ‘ORDER BY’ field of the pods-list-element, I get the error message -> ‘Pods Embed Error:?ORDER BY contains SQL that is not allowed.’.

    I have tried t.post_date ASC, t.post_title ASC, but it doesn’t matter what I put in, the error keeps appearing.

    I’m new to using pods. Maybe I’m doing something wrong. Or is this a bug?

    There’s another thing I’ve noticed regarding the language setting but I’ll open up a new thread for that.

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

    (@keraweb)

    Hi @rico34

    Please check the Pod access settings, it seems that you didn’t allow these manual SQL options for this post type.

    Cheers, Jory

    Thread Starter rico34

    (@rico34)

    Hi Jory,

    thanks a lot for your quick reponse! Very much appreciated.

    I changed the setting under ‘Pods Admin’>’Settings’>’Allow SQL clauses to be used in Dynamic Features’ to ‘Restricted – Enable Simple SQL…’.

    Now it works. But since I don’t want to give all content creators this SQL abilities, I will turn this off again. So to get my Pods template to show the content with an orderby sort I have to create and somehow use it with a custom php template I guess. Is my assumption correct?

    Thank you,
    rico

    Plugin Support Paul Clark

    (@pdclark)

    Yes a custom PHP template or a new shortcode using pods->find() and pods->template().

    For example, for shortcode [ordered_template_of_things]:

    <?php
    /**
     * https://developer.www.ads-software.com/reference/functions/add_shortcode/
     * https://docs.pods.io/code/pods/find/
     * https://docs.pods.io/searching-filtering-sorting/sorting/sorting-date-fields-using-cast/
     * https://docs.pods.io/searching-filtering-sorting/complicated-where-sort-and-filters/using-date-based-searches/
     */
    add_shortcode(
    	'ordered_template_of_things',
    	function( $atts = [], $content = '', $tagname ) {
    		$maybe_output = pods(
    			'post_or_page_or_cars_or_kittens',
    			[
    				'limit' => 20,
    				'orderby' => 't.post_title ASC',
    			]
    		)->template( 'Name of the Template' );
    
    		if ( ! empty( $maybe_output ) ) {
    			return $maybe_output;
    		}
    
    		return sprintf(
    			'<p>There are no cars or kittens. Today is %s.</p>'
    			esc_html( date('l') )
    		);
    	}
    );

    Where the Pod name is post_or_page_or_cars_or_kittens, it is ordered by post_title, the template name is Name of the Template, and if no content is found, it will display There are no cars or kittens. Today is Tuesday.

    The orderby query for post_date would be CAST( t.post_date AS DATETIME ) DESC

    Reading the docs for add_shortcode will reveal that anything passed as an attribute="value" in the new shortcode will be available to the function as $atts[ 'attribute' ].

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Getting Error when setting order by for pods item list block’ is closed to new replies.