How to create frontend Post filter using meta query

I have created a post filter like the image below, but I have an issue with selecting multiple values from different fields. All the fields in the filter are custom fields. The thing is, in the admin panel, one post has a select field with city Telaviv and with a select field Property Type with a value Garden Apartment. The other post has a different city and Property Type as Ground Apartment. On the front end, if I choose from …
Category: Web

Query posts(CPT, pages , hierarchical) by Ancestor ID

so i have a custom post type with hierarchical structure. Looks like this: top level 1 - child -- grand child -- grand child - child -- grand child top level 2 - child -- grand child -- grand child - child -- grand child top level 3 and so on. I need a query with top level id as a base and query through all child and grand child pages of that top level page? I know ther is …
Category: Web

wp parse_query not working with custom meta value

I've a custom post type with some custom meta box. I want to filter my custom post type posts using custom meta value. I've written the code below. But it return no post found. Can anyone tell me where I did wrong? Here is the codes. <?php add_action('restrict_manage_posts','restrict_listings_by_metavalue'); function restrict_listings_by_metavalue() { global $typenow; global $wp_query; if ($typenow=='jspp_std') { echo '<input type="text" name="adate" id="adate" placeholder="Enter Admission date" />'; } } add_filter('parse_query','jspp_custom_meta_query'); function jspp_custom_meta_query($query) { global $typenow; global $pagenow; if( $pagenow == …
Category: Web

How do I add a separator to my list of terms with get_category

I have this... $args = array('child_of' => 3422 ); $categories = get_categories( $args ); foreach($categories as $category) { echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all members in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> '; } I can't find a way to add a separator between each term?
Category: Web

Display all posts from specific category and CPT

Currently, we are getting all posts from a specific category using the following: $args = array( 'post_type' => array('post'), 'cat' => 1247, 'posts_per_page' => 4 ); What we'd like to do is get all posts from cat 1247 and also from custom post type 'videos', such as: $args = array( 'post_type' => array('post', 'videos'), 'cat' => 1247, 'posts_per_page' => 4 ); However, as none of the posts in 'videos' are from category '1247', it's only showing posts from '1247', however …
Category: Web

$args for get_terms() to return ORDER BY FIELDS

I want to use get_terms() for a taxonomy in such as way as to emulate MySQL's ORDER BY FIELD e.g., ...FIELD ('aaa','ccc','bbb','eee','ddd') A var_dump snippet currently looks like: object(WP_Term)#1861 (10) { ...["slug"]=> string(3) "eee" object(WP_Term)#1862 (10) { ...["slug"]=> string(3) "bbb" object(WP_Term)#1863 (10) { ...["slug"]=> string(3) "aaa" object(WP_Term)#1864 (10) { ...["slug"]=> string(3) "ccc" object(WP_Term)#1865 (10) { ...["slug"]=> string(3) "ddd" Have been reading the codex but I'm missing something. Here's what I have: $args = array( 'orderby' => 'include', 'order' => 'ASC', …
Category: Web

How to modify a taxonomy that's already registered

Today I needed to change the arguments on a custom taxonomy that was already registered by a third party plugin. Specifically I wanted to set the show_admin_column argument to true and change the rewrite slug so that it wasn't just the taxonomy slug. In this case, it was a "People" post type with a "People Category" custom taxonomy. I was surprised this wasn't asked before, so here's a question and answer.
Category: Web

Include search tags and users in my search results system

This is my codes for search posts by ajax: PHP: public function search_posts(){ try { $data = $_POST['content']; $data = wp_parse_args( $data, array( 'post_type' => 'post', 'post_status' => 'publish', ) ); if ($data['s']){ global $theme_query; $theme_query['s'] = explode(' ', $data['s']); } $query = new WP_Query($data); $data = array(); foreach ($query->posts as $search_post) { $search_post = get_post($search_post); $search_post->permalink = get_permalink($search_post->ID); $data[] = $search_post; } $search_term = $_POST['content']['s']; $resp = array( 'success' => true, 'data' => array( 'posts' => $data, 'total' => …
Category: Web

Custom Taxonomy Archive BUG

I'm hoping that Its just my tired eyes missing something and a fresh pair of eyeballs might catch what I'm missing. I have a custom taxonomy with a slug of 'residential_project_types' that is assigned to a custom post type of residential_projects. I want to display all terms from the taxonomy, outputting the term name and link. Its KIND OF working... Instead of displaying a single term for each, it appears to be displaying a term for every post included in …
Category: Web

Remove h2 Tag in screen_reader_text

How can I remove the h2 tag used in the screen reader text? I use the following $args, but h2 is still in it: the_comments_pagination( array( 'add_fragment' => '', 'screen_reader_text' => __( '<h3>Test</h3>' ) ) );
Category: Web

How to pass a variable for key/value pairs in an argument?

For example, this works: 'default' => '#ffffff' But this does not: $white = '#ffffff'; 'default' => $white How can I pass variables to key/value pairs? Here is a more complete example for some context: $white = '#ffffff'; $transport = 'refresh'; $wp_customize->add_setting('mytheme_text_color', array( 'default' => $white, 'transport' => $transport )); In reply to jgraup: This code works: $wp_customize->add_setting('themeone_primary_nav_background_color', array( 'default' => '#181818', 'transport' => 'refresh' )); This code doesn't: $args = array('default' => '#181818', 'transport' => 'refresh'); $wp_customize->add_setting('themeone_primary_nav_background_color', $args); When I …
Category: Web

Custom nav walker: How to acces the $args parameter?

I am creating a custom nav walker. I noticed that the nav walker class from the WordPress core is written rather rough – much of the stuff going on could be spread out through various methods, so I wanted to give that a try. Currently I am wondering how I can get the $args (containing arguments passed to different methods) parameter in my constructor? Giving it a close look, there is the filter wp_nav_menu_args (source) that could be used for …
Category: Web

How to orderby meta_value_num with dollar ($) sign

The custom fields all have prices including $ signs, and a dot as separator. $theQuery = new WP_Query(array( 'orderby' => 'meta_value_num', 'meta_key' => 'price', 'order' => ASC )); All formatted like this: $24.95 $190.00 $1.40 They won't sort correctly due to the dollar sign, is it possible to ignore or remove the first character / $ sign in this WP_Query?
Category: Web

Ajax form filter post by custom fields

I'm currently working on a site where users can search for apartments. I have a custom post type for the apartment posts, which contain several custom fields. I have a page where i list all of the apartments. What i want to do is have a form, containing check boxes, drop-downs and radio button, where the user can filter apartment posts by custom fields. For example by price or size. So when the users clicks on an check-box for example …
Category: Web

post__in - Placing content from a foreach loop inside of an array

I know this code is incorrect, but it's a basis of what I am trying to achieve. I am parsing an xml feed via PHP and running a foreach loop to get a value from a specific key. Here is the snippet I am using: $feed = file_get_contents("https://www.feedurl.com/xml"); // Feed URL $xml = new SimpleXmlElement($feed); $output = array(); foreach($xml->entry as $entry){ $attributes = $entry->id->attributes(URI_RSS); $im = $entry->children(URI_RSS); // Get item's ID $id = $entry->id; $attr = $id->attributes('im', TRUE); $output[] = …
Category: Web

How to implement time filter to show random post 1 month for one category and 3 months for other categories

I started to work on one website after another developer and there is problem with his "popular widget" which is basically showing 3 random posts from category. There is some Switch statement which is regulating to show from category news 3 random post not older then 1 month and for other categories 3 month. I don't understand what he did there with ['interval'] but when I use wordpress time parameters still I don't have results. function getSomePost($category,$postsPerPage=3) { global $post; …
Category: Web

Get WP_Query query after execution?

It it possible to get the configuration of a the latest called WP_Query? I need to use it for debugging. For example, if i run something like: $the_query = new WP_Query( $args ); ... Could i get the $args array later by doing something like $the_query->args(); or something?
Category: Web

Using wp_parse_args to set up Plugin Default Settings

So I want to have defaults set up for each of my plugins settings, and I'm using wp_parse_args to do so which I believe is the correct way, but I'm hitting a roadblock. Here's my code at the moment: function eddslider_options_each( $edd_slider_options ) { $edd_slider_options = get_option( 'eddslider_options' ); /** * Define the array of defaults */ $defaults = array( 'slider_insert' => 0, 'slider_arrows' => 0, 'slider_bullets' => 0, 'slider_effect' => 'fade', 'slider_theme' => 'default' ); /** * Parse incomming …
Category: Web

Creating a Search Array From Multiple Tables

I'm working with a client's WordPress site that has user submissions (via TDO Mini Forms) from multiple countries, and they would like to be able to search for posts by region – Europe, Africa, Central America, etc. There is a custom field already in place for the user's country of origin. I also have a separate table that maps countries to regions. What I want to do is make it so that the user can select Europe, for example, from …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.