Misc functions

Some misc functions that may be useful.

Modify wp query to automatically add meta_key for a field and fieldgroup

This way it’s very easy to sort posts by a text field or date picker.

// dynamically add the custom key for a field to the meta_key argument
$args = array(
	"orderby" => "meta_value",
	"sf_meta_key" => "my_fieldgroup_slug/my_field_slug",
	"order" => "asc"
);
$my_query = new WP_Query($args);

// would be the same as
$args = array(
	"orderby" => "meta_value",
	"meta_key" => "_simple_fields_fieldGroupID_2_fieldID_0_numInSet_0",
	"order" => "asc"
);
$my_query = new WP_Query($args);

Some other useful things



// Extends args for WP_Query() with simple fields meta query args
// and returns query result object
function simple_fields_query_posts($query_args = array()) {

/**
* Return the name of the post connector for the current post in the loop
*
* @return mixed False if no connector or connector not found. String name of connector if found.
*/
function simple_fields_connector() {

/**
* Checks if the current post in the loop has the connector with slug $slug selected
*
* @param string $slug Slug of post connector to check
* @return bool
*/
function simple_fields_is_connector($slug) {

 

3 thoughts on “Misc functions

  1. Pascal

    Hi !

    I use the get_page($ID) to display several pages on one page. I would like to display the custom fields of those pages too, and for that, I need to test which connector is used for each page like that:

    if(simple_fields_is_connector(‘name_of_connector’) == true){ …. }

    It works for the first page, but for the following pages, it doesn’t recognize which connector it is (it still uses the connector of the first page)…

    Do you have an idea why ?

    Thank you !

Leave a Reply