Tag Info

New answers tagged

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) { ...


1

The child_of parameter excepts an integer value of the specific term you need to get descendants from. This means that you need to get the ID from the On-going category term and then passing that ID to the child_of parameter. To note, the child_of parameter returns all descendants of the term passed, this includes direct children and all children of those ...


0

You should use get_the_categories() Returns an array of objects, one object for each category assigned to the post. This tag may be used outside The Loop by passing a post id as the parameter. $categories = get_the_categories(); var_dump( $categories );


-1

Set 'posts_per_page' to 1 on your args variable. I also suggest that you add 'page-attributes' while registering the magazine's post type and order the result by 'menu_order'. This way, you will have the field Order while editing a magazine, and set the highest which should appear on this query.


1

There is a build in function for this already, no need to create a custom function for this. The function is called get_term_children() and will return either An array of child terms if the given term have children An empty array if no child terms are found WP_Error object if the taxonomy does not exist With this in mind, wrap get_term_children() in a ...


0

This is what I use. The variable $cat is the category ID you are checking: $categories = get_categories($cat); if (!empty($categories)) { // This Category has children } else { // This category has no children }


0

Following code will fetch custom taxonomies named products. Array of taxonomy object will be returned. Use foreach for loop. In the following example, taxonomy name and description is printed out. $customPostTaxonomies = get_terms( 'products' ); if ( ! empty( $customPostTaxonomies ) ) { foreach ( $customPostTaxonomies as $key => $tax ) { echo ...


0

Use this instead of wp_list_categories( $args ); wp_list_categories( $args ); It will display the category with formatted results like <ul><li> $categories = get_the_category(); This will returns the all category assigns to the current post and store in $category variable. Then you can display as in you listed format ...


0

Figured it out :) It ends up the Smarter Navigation plugin has a few other functions that I missed: https://plugins.trac.wordpress.org/browser/smarter-navigation/trunk/template-tags.php I used get_adjacent_id_smart() like so: <?php $prev_post = get_adjacent_id_smart(true); if(!empty($prev_post)): echo 'not empty'; ...


2

In order for this to work, you will need to know from where the single post was refered from and if the referrer is a valid one. Secondly, we need to adjust pagination between single posts in order for us to pass our referrer between single posts. The problem with referrers is, they are set and controlled by user side. Referrers can be disabled or blocked ...


0

First query all post $args = array( 'post_type' =>'posts', 'post_status' =>'publish', 'posts_per_page' =>-1 ); $query = new WP_Query($args); $post_ids = array(); if($query->have_posts()){ while ($query->have_posts()){ global $post; $query->the_post(); ...


0

What's the simplest way to spit out a single category as a title in an H2 tag for a post with multiple categories? $c = get_the_category(); if (!empty($c[0])) { echo $c[0]->name; } I have no idea how or why sessions would come into that.


0

How about using get_the_terms filter like this,, add_filter('get_the_terms', 'hide_categories_terms', 10, 3); function hide_categories_terms($terms, $post_id, $taxonomy){ // get term to exclude by name, by id or maybe by slug $exclude = get_term_by('name', 'feature', 'category', ARRAY_A); if (!is_admin()) { foreach($terms as $key => ...


0

I tend to not use any of the get_posts() parameters as given in the codex, I usually make direct use of the parameters available to WP_Query as they are all valid with get_posts() anyhow The parameters of get_posts() gets converted to valid parameters before being passed to WP_Query. Any parameter passed to get_posts which is not a valid parameter of ...


0

get_posts() passes the data to WP_Query as the cat argument as you can see in the source: 1863 if ( ! empty($r['category']) ) 1864 $r['cat'] = $r['category']; There is also a note in the source that is relevant: 1835 * @type int|string $category Category ID or comma-separated list of IDs (this or any ...


0

Display posts that have "all" of these categories: $query = new WP_Query( 'category_name=staff+news' ); See this on category parameters.


1

I think you should check for some other platform. WordPress is made to be live all the time : ) But if you are really keen in doing it in WordPress I can suggest a hard way of doing it. You can use the JSON-REST-API for WordPress and jQuery Mobile to build a mobile app that will run on any browser (not only mobile browser). Thank with cache manifest and ...


0

the arguments for your query would be like $args = array( 'post_type' => 'articles', 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'name', ...


0

No, you cannot create an alias for term names. But if you could, it would not be the optimal or easiest method. Instead of having a single taxonomy were the top level is the OS, the children are the price, and the grandchildren are the app category, instead have 3 taxonomies: Operating System ( iOS/Android/etc ) Pricing ( free/freemium/paid/etc ) App ...


0

Since you're not currently running a multi-site install, you can either install the WP-REST-API plugin which is currently in beta, or you can wait for it to hit core which will probably be around version 4.3 or 4.4. If you were on a multi-site install, you could have easily used the switch_to_blog() function to switch between blog databases to query ...


2

The relevant code is here: query_posts("cat=25&orderby=DESCd&showposts=3&$randomArticlesNum&caller_get_posts=1"); That is the query that is pulling the posts, and that is what you want to alter. Your previous theme builder also did something that should never be done-- used query_posts(). Also, both showposts and caller_get_posts have ...


2

So, i used this script in the end, thanks to Pieter Goosen's post Category Alphabet List Broken $terms = get_terms('anime-on-going'); if ( !empty( $terms ) && !is_wp_error( $terms ) ){ $term_list = []; foreach ( $terms as $term ){ $first_letter = strtoupper($term->name[0]); $term_list[$first_letter][] = $term; } unset($term); ...


0

Found the solution. I am using get_next_post() and get_previous_post() functions which works perfectly.


0

gdaniel, thank you for your reply, but actually I mean different : 1) show missing fields in my post_type listing 2) modify categories block, not to add/delete categories, but always show 2 existing categories, as they are constants for my post_type .


0

WordPress search only handles posts, it doesn't handle taxonomies and their terms ( tags, categories etc ) If you want more advanced search you'll have to use a 3rd party solution


0

Try going to your permalinks page within the admin to flush the rewrite rules. Just be navigating to that page will flush the rules, but you could click save even if you made no changes.


1

Found the solution. Simply add $args = array( 'parent' => '0', ); at the top, and change $cats = get_terms('category'); to $cats = get_terms('category', $args); There are more values, see https://codex.wordpress.org/Function_Reference/get_terms


4

The error says it all, you are sending the request to a invalid host. Change this: var ajaxurl = 'http://my-site.co.uk <?php bloginfo("wpurl");?>/wp-admin/admin-ajax.php'; To: var ajaxurl = "<?php echo esc_js( admin_url( 'admin-ajax.php' ) ) ?>"; Note: from your code and description I'm assuming you are generating the jQuery code within ...


0

Don't let the fields be set to null or unset altogether. The queries needed to get that data are not efficient. Set your field to "no" or some other value. function save_details(){ global $post; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post->ID; } $valid = array( 'yes' => 'yes', 'no' => 'no' ); ...


2

To make this more complete, here is what I have said in comments in reply to the question on hand Just to quickly explain, WP_Query fails catastrophically in some cases where empty arrays are passed to some of its parameters, instead of also returning an empty array as we should expect, WP_Query returns all posts. As for getting the correct stickies, as ...


1

The answer to both issues was pretty simple. Simply add an argument to WP_Query to limit to the current category Make sure that WP_Query doesn't run unless there's actually some sticky posts Like so: <?php // Get sticky posts $sticky_ids = get_option( 'sticky_posts' ); // BEGIN Custom "sticky" loop // If sticky posts found... ...


1

This question as mentioned in the comments is not related to wordpress by any means. But anywho remove the float on your #portfolio-item and add some flex like its 2015. #contentportfolio { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-flex-wrap: wrap; -ms-flex-wrap: wrap; flex-wrap: wrap; } ...


1

You've probably solved this, but for anyone else that needs this: $wp_taxonomies['category']->update_count_callback = '_update_generic_term_count'; This is significant in the case of attachments. Because an attachment is a type of post, the default _update_post_term_count() will be used. However, this may be undesirable, because this will only ...


0

You need to sort the categories to make sure they come in the correct order: // get categories of post in sorted order $categories = sortCategories(get_the_category()); function sortCategories($categories) { // Sorting the category usort($categories, "cmpCategories"); return $categories; } function cmpCategories($category_1,$category_2) { // ...


1

you need to sort the categories first. // get categories of post in sorted order $categories = sortCategories(get_the_category()); foreach($categories AS $category) { echo $category->name; // Plot category name } echo get_the_title(); // Plot post name function sortCategories($categories) { // Sorting the category usort($categories, ...


1

Working off of Pieter Goosen's answer to this question, the way around this is to create a list of all the categories except the one you want to exclude, then search for posts that include them. That way, if a post has the excluded category but also other categories, it'll be included. So, in my case: $args = array ('exclude'=>1,'fields'=>'ids'); ...



Top 50 recent answers are included