Tag Info

New answers tagged

0

If you save $jobcatsvalue make sure if it's an array of integers when saving. // Format the taxonomies if(is_array($_POST['jobcats'])){ foreach($_POST['jobcats'] as $j){ $jobcatvalue[] = intval($j); } } else { $jobcatvalue = array(intval($_POST['jobcats'])); }


-2

use this code for access first texonomy from custom post type in wordpress how about use get_the_terms() function? please try this code $works = get_the_terms( $post->ID, 'work' ); $director = $works[0]; // print object from first director print_r($director); // or get the director name echo $director->name;


0

how about use get_the_terms() function? please try this code $directores = get_the_terms( $post->ID, 'directores' ); $director = $directores[0]; // print object from first director print_r($director); // or get the director name echo $director->name;


0

Here is how i accomplished this.. Inside of the admin_menu action, I added a submenu item to the parent menu item ('nwcm') with the URL parameter of the taxonomy edit page. add_submenu_page('nwcm', 'News categories', 'News categories', 'edit_posts', 'edit-tags.php?taxonomy=nwcm_news',false );


3

Always great if someone wants to use better, more correct and more efficient ways to get things done. To achieve what you need is not difficult. WORKSFLOW: Use the usort() to create your custom sort order Use the the_posts filter to sort and return the sorted array of posts just before the loop is executed Inside the loop, all you need to do is to ...


2

If I understand the question correctly, you want to produce something like this: Sub-Item 1 Post 1 Post 2 [...] Sub Item 2 Post 1 Post 2 [...] There may be a more efficient way than what I am about to tell you, but I would try something like this: First create an array to hold your sorted posts. $sortedPosts = array(); Next, create an array for ...


1

You have one or two issues here and possible future bugs that you might encounter term in your tax_query should be terms Be carefull with terms having dates as names and especially dates as slugs. This can cause issues and unexpected results if custom permalinks clash or if something falls into the template hierarchy for some reason. Never use the name ...


0

i.e. register a custom taxonomy MY_NEW_CARSS for custom post types: $my_taxon_name = 'MY_NEW_CARSS'; $my_post_types = array('SUB_CAT_1','SUB_CAT_2','SUB_CAT_3'); //REGISTER CUSTOM TAXONOMY ( http://codex.wordpress.org/Function_Reference/register_taxonomy ) //If you aim to register HIERARCHICAL(Parent-ed) post type, read this warning: ...


0

The solution to this was pretty simple.Had I read WP documentation thoroughly for get_categories Apparently I had to set this 'hide_empty' => false when I fetched my taxonomies :)


1

Are you using Advanced Custom Fields plugin? If you are, try this if it works: foreach ($terms as $term) { // $cognome_nome will be "P Elena" or "P Andrea" in your case $cognome_nome = get_field('cognome_nome', $term->taxonomy.'_'.$term->term_id); }


0

I think the best option would be is to use your getPostViews() count and incorporate a system in there to append the trending term to the post once your counter hits 150. Here is our worksflow Get the post view count (which you are already doing) Compare the current count to the desired 150 Use wp_set_object_terms() to append the trending term to the ...


1

Use get_terms() to get the child terms of a given term. You need to feed the specific term id to either parent  (integer) Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string. OR child_of - (integer) Get all descendents ...


1

Before I start, you have a bug in your code which you should have picked up if you had debug turned on. You are first assigning $r['cat'] to a variable before even checking if $r['cat'] is set. Because cat is not a default, it may not be set, which will cause a PHP error when cat is not set. You can refactor your code to something like this: (Requires ...


0

No Category is an taxonomy but not an custom taxonomy. Custom taxonomies need to be created via code, and you will have an different type of categories.


1

You have a lot of issues here: You should not be using $_GET variables without sanitizing it. Never ever trust any user inputs and URL parameters. They might contain malicious code which can harm your site. To sanitize and validate a $_GET variable, use the filter_input php function $filtered = filter_input( INPUT_GET, 'type', FILTER_SANITIZE_STRING ) ...


0

I had a similar issue and was able to resolve the improper menu behavior by using the parent_file filter. $parent_file is set in the /wp-admin/edit-tags.php file, but it needs to be altered based on your use case. add_filter('parent_file', 'filter_subscriber_menu'); function filter_subscriber_menu($file) { $screen = get_current_screen(); if ...


0

With Wordpress 4.2.2 I'm using the following (admittedly fragile) method to search excerpts as well as the content and title without a plugin. This is the relevant snippet from functions.php. add_filter('posts_where', 'custom_posts_where'); function custom_posts_where($where) { if (is_search()) { $where = preg_replace( ...


0

The custom query to get custom post type posts filtered by 2 different terms from 2 different taxonomies will be: $args = array( 'post_type' => 'listing', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'job_listing_region', 'field' => 'slug', 'terms' => ...


0

If your URL structure is valid and correct, all you need then is the default loop. The main query runs on each and every page request, and the parameters passed to WP_Query ( yes, the main query also uses WP_Query) is determined by the URL and rewrite rules for that specific page. If your URL structure is a valid structure and matches a true page request ...


0

category.php template file is only for core categories taxonomy. The equivalent for custom taxonomies is taxonomy.php. See template hierarchy for more information.


1

The following does pretty much what @TheDeadMedic did at his answer good answer, brought me there half the way, so this is kind of just an addition to it. Out of personal preference I opted to do it with start_el. → make sure to replace YOUR-TAXONOMY in below code according to your needs add_filter( 'wp_terms_checklist_args', ...


0

I solved this by passing the array of terms into a sorting function. The array is passed by reference so nothing needs to be returned: function sort_object_terms(&$terms) { global $wpdb; // First get an array of just the term IDs $term_ids = array_map(function($term) { return (int)$term->term_id; }, $terms); // Now get ...


0

Try this, it may help: if( !defined( 'ABSPATH' ) ) exit; function modify_wp_search_where( $where ) { if( is_search() ) { global $wpdb, $wp; $where = preg_replace( "/($wpdb->posts.post_title (LIKE '%{$wp->query_vars['s']}%'))/i", "$0 OR ( $wpdb->postmeta.meta_value LIKE '%{$wp->query_vars['s']}%' ...


1

Hey anyways I found with an exact answer which works as a charm. I hope it would be helpful to someone so I am posting it over here. First you need to add the following code in function.php /** * Custom post type date archives */ /** * Custom post type specific rewrite rules * @return wp_rewrite Rewrite rules handled by Wordpress */ ...


-1

Just pass array with category terms in wp_set_post_terms taxonomy parameter. global $post; $post_id = $post->ID;//get the current post id $terms = array('term1','term2'); $taxonomy = 'category'; $append = false; // or true wp_set_post_terms( $post_id, $terms, $taxonomy, $append );


0

put this code in functions.ph define('IMAGES',get_stylesheet_directory_uri().'/img'); where img is the directory where the images for the flags are present <?php get_header(); $queried_object = get_queried_object(); $term = $queried_object->name; switch ($term) { case "china": echo '<img src=" <?php ...


0

You coudld just use $housePhotos = get_post_meta( $post->ID, 'house_photos', true ) to get an array of the image id's. Then you could get the first image by saying $imageURL = wp_get_attachment_image_src( $housePhotos[0], 'house_search' );


0

Try this: $post_types = array("partner", "post"); // List the post types that you want to query foreach ($post_types as $post_type) { echo '<p>' . $post_type . '</p>'; $query = new WP_Query(array( 'posts_per_page' => 3, 'post_type' => $post_type ) ); // The Loop if ($query->have_posts()) { echo '<ul>'; ...


0

Your way of expressing yourself is confusing, probably because you don't quite master the terms you are using but it's OK. What you mean to say is that you need to fetch several posts with different post type formats. I would just use meta data to link am Event Leaders post to the other two post types. Or there is this plugin called Posts 2 Posts that might ...


0

This depends on how your theme handles Taxonomy pages. If it e.g. has a category.php that does stuff different than taxonomy.php or archive.php this is the reason. Have a look here to see how the template hierarchy works.


0

You just need to use get_post_types() and loop through foreach to get all registered post type. $post_types = get_post_types( '', 'names' ); foreach ( $post_types as $post_type ) { echo '<p>' . $post_type . '</p>'; } See details in WordPress Codex https://codex.wordpress.org/Function_Reference/get_post_types


-1

i think you posted the different code earlier. But if this is the code you are using right now then you should so this $slide = new wp_query( array ( 'post_type' => 'banner' , 'tax_query' => array( array( ...


-1

this code will display the post from all taxonomy in wordpress: $args = array( 'type' => 'post', 'child_of' => 0, 'parent' => '', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'hierarchical' ...


0

From what I understand you have a loop that displays up to 500 pages. If the page parent = 18219 than you want to query the tags for that page. As far as I know, by default WP does not allow you to tag Pages, only Posts. But let's pretend you have a plugin that allows you to do that... Inside your loop you can check to see if the page has a parent equal to ...


0

Looking at the function update_woocommerce_term_meta(), you would recognize it just uses the wordpress function update_metadata(), which essentially means that woocommerce is using meta values, just like you do in you CPT. With this in mind, I wouldn't think this procedure would slow down your site + your keeping compatibility by using existing functions. ...


1

The simple and quickest solution is showing categories list by using sitemap plugin with short-code. For example this plugin WP Sitemap Page. Install it and place shortcode on page. Second option is create page template for category list. Using wp_list_categories() Thanks


1

To get a list of categories when you visit yoursite.com/topics or even the default yoursite.com/categories (doesn't matter; it's not a link structure related issue) you have to have a template for this. It's like a sitemap. If you want to show a sitemap on your front-end, you'll have to have a sitemap template. In this case, it's a category archive what ...


0

Okay, it seemed that going with more than 1 taxonomy was just wishful thinking. I settled with this: CPT still is 'magazine' Hierarchical taxonomy terms were used instead: Parent: The author name Children: The magazines that each author will publish. With the code below I managed to get a working taxonomy-authorname.php page: <?php $taxonomies = ...


2

You can follow similar approach with get_the_terms. Here is the function. function add_taxonomy_to_single( $classes ) { if ( is_single() ) { global $post; $my_terms = get_the_terms( $post->ID, 'custom-taxonomy' ); if ( $my_terms && ! is_wp_error( $my_terms ) ) { foreach ($my_terms as $term) { ...


0

I just ran into this issue recently. If you are using a Custom List Table (A/K/A WP List Table) within a Meta Box (located on the post edit screen post.php or post-new.php.) The reason you get redirected to the posts listing screen (edit.php) is because you're Custom List Table generates a hidden nonce field, which is also generated by the post.php or ...


0

This question has different answers in this specific Wordpress question, they may be of help: Display all posts in a custom post type, grouped by a custom taxonomy Personally I used this method that worked for me just fine: $terms = get_terms('tax_name'); $posts = array(); foreach ( $terms as $term ) { $posts[$term->name] = get_posts(array( ...


0

Try like this $args = array( 'post_type' => 'movie', 'tax_query' => array( array( 'taxonomy' => 'producer', 'field' => 'slug', 'terms' => 'WarnerBros', ), ), ); $query = new WP_Query( $args ); See more at wordpress codex



Top 50 recent answers are included