1. Home
  2. Docs
  3. Simpods MVC
  4. Tutorials
  5. Featured Methods
  6. simpods_select_fn()

simpods_select_fn()

simpods_select_fn is built to facilitate data queries for some Simpods components like Hierarchy and Linked Area, but you can use it as a normal query function.

Parameters

simpods_select_fn accepts four parameters:

simpods_select_fn( $fields_arr = array(), $atts_arr = array(), $echoQuery_bln = false, $prefixMe_bln = true )
  • $fields_arr: Pass in an associated array to search table fields, in this format: array(‘field_name’ => ‘value’). For example, if you want an exact match of “hello” in post_name, create an array like this: array(‘post_name’ => ‘hello’); To search one value in many options, arrange the options in an array, e.g. array( ‘post_status’ => array(‘publish’, ‘pending’) ). Combining the two examples above, the $fields_arr will be
    array('post_name' => 'hello', 'post_status'  => array('publish', 'pending') )
    

    If a Pods table is the main table you are querying, please add post_tb. before the fields of the WordPress posts table, e.g.

    array('post_tb.post_name' => 'hello', 'post_tb.post_status'  => array('publish', 'pending') )
    

    There some prefixes to added to the field_name to meet different search criteria:

    • _exc_ Search will return all rows except those with the field that matches the value. e.g. array(‘_exc_post_name’ => ‘hello’);
    • _find_ Search will return all rows with the field that contains the value. e.g. array(‘_find_post_name’ => ‘hello’);
    • _prev_ If search order is set to ASC, search will return the row previous to the one that contains the value. e.g. array(‘_prev_post_name’ => ‘hello’);
    • _next_ If search order is set to ASC, search will return the row after to the one that contains the value. e.g. array(‘_next_post_name’ => ‘hello’);
  • $atts_arr: Pass in an associated array to construct the query, in this format: array(‘key’ => ‘value’).  Below is the default one. If your keys are not listed in the default array, they will be ignored. If they exist, your values will overwrite the existing ones.

		$defaults_arr = array(
			'target_tb'    => '',         // The target database table
			'limit'        => 0,          // Max number of results to return
			'order'        => 'ASC',      // Search order. _prev_ and _next_ only work with ASC
			'order_by'     => '',         // Field to order the results by
			'group_by'     => '',         // Group your search results
			'start'        => 0,          // Which row to start the search
			'cat_areas'    => array(),    // For Simpods Hierarchy: array( array( 'join' => AND|OR, 'cattb' => number, 'catid' => number ) )
			'inc_cats'     => false,      // If true, all Simpods Hierarchy categories will be unserialized and included
			'linked_areas' => array(),    // For Simpods Linked Area: array( array( 'join' => AND|OR, 'cattb' => number, 'catid' => number ) )
			'inc_areas'    => false,      // If true, all Simpods Linked Areas will be unserialized and included
			'scheduled'    => false,      // If scheduled, outdated posts won't be included. Only work if the Simpods Schedule Component is available.
			'count_only'   => false,      // If true, the search will return the number of how many rows found only, no values of the fields will be returned. It is useful for pagination. Usually you will have to run another query for the count_only. 
			'term_id'      => 0,          // The term id, like the post category id or custom taxonomy id.
			'search'       => '',         // Extra bits that are not included in the function, expect escaped. e.g. AND main_tb.field = "something" AND post_tb.post_name = "something"
			'join'         => '',         // Extra join queries, expect escaped
			'fields'       => '',            // Extra fields to return, usually needed when you use 'search' and 'join' above string or array e.g. Expect escaped.
			'fields_only'  => false,	 // if true, only the fields in the fields option will be returned.	
		);
  • $echoQuery_bln: Default to false. If set to true, the SQL query will be displayed on the screen, for debugging purpose.
  • $prefixMe_bln: Default to true. If set to false, the function won’t automatically prefix $table_prefix to the ‘target_tb’ in the $atts_arr array. It is useful if you are querying a database table that are not designed for WordPress.

main_tb and post_tb

An alias “main_tb” will be created for the “target_tb” in the query. If the function detects that it is a post type created by Pods Framework, it will return data from the WordPress posts table as well. The alias for the WordPress posts table is “post_tb”. Please use them accordingly in your extra ‘search’ and ‘join’ queries.

Return

This function will return the results in an associated array.