New answers tagged

0

It seems the above solution did not work so well for me (as @slowaways mentioned earlier, with WordPress 5+). So I came up with a new solution. Since I am using ACF, I created a new 'short description' field ('extrait') and made it mandatory. So I can use the validation features of ACF, and update excerpt value on the fly : /** * Set excerpt from ACF field ...


0

Add Below Code For post title, page title, category title , tag title , taxonmy title , Author title . According to your Needed. function page_title_sc( ) { $title = ('Page Title'); if ( is_page() || is_singular() ) { $title = single_post_title(); } else if ( is_category() ) { $title = single_cat_title( '', false ); } else ...


0

I'm not completely sure what you want to do but is_page will check for a page and exclude (custom) posts. If you want the condition to work for posts you will need is_single. If you want the condition to work for both posts and pages you will need is_singular. That said, going this path may not be the smartest thing to do, because you will be polluting your ...


1

In this case, since there's a many-to-many relationship between movies and actors, I recommend making them two separate pods with a relationship between them. See the intro video at https://pods.io/ ... I don't remember where he explains relationship fields but it's all in there. You don't need to use PHP if you don't want to. You could use Pods templates (...


0

Check this tutorial to perform this task. Url - https://www.wpbeginner.com/wp-tutorials/how-to-display-recent-posts-from-a-specific-category-in-wordpress/


0

Anyone coming across this question who has encountered the dreaded link rot with the "following script" link mentioned in the question, here's the script courtesy of the Wayback Machine, with a correction to what I believe was an error in the code: /** * Remove the slug from published post permalinks. Only affect our CPT though. */ function ...


1

When you declare your "Arrangements" custom post type, be sure to add 'author' and 'breadcrumbs' as parameters to the "supports" array. For example, it might look something like: $supports = array( 'title', 'author', 'breadcrumbs', 'editor', 'excerpt', '...


0

How to make your AJAX filter works properly: As I said in the comments, add the data-category attribute to the <a> having the CSS class js-filter-item in the foreach loop in your archive-projetos.php template: // * Wrapped for brevity. foreach ( $categories as $cat ) : ?> <li><a class="js-filter-item" href="<?=...


0

via: https://cnpagency.com/blog/the-right-way-to-do-wordpress-custom-taxonomy-rewrites/ I needed to change the order of registering the taxonomy (make sure it's before CPT) and the CPT (make sure it's after registering any taxonomy). Now 'rewrite' => array( 'slug' => 'resources/tags', 'with_front' => false ), works as expected!


0

Is there a way to remove the "View" link under the users in the backend User panel? All users are listed with an Edit, Delete, View link. I'm looking to remove that View link. Much appreciated.


0

As I understood you want to be able to add Students from the Teachers post type and assign them directly to the current teacher. Is it impossible? I don't think so but definitely not an easy task to pull off. You are going to have to manually write all the code the outputs a form inside the Teachers post type and create a Student according to the data filled ...


0

Refer Link for Your Knowledge Template Hiearchy for a more detailed break down of how WordPress chooses the template For a taxonomy term slug ('sports' your example) in the taxonomy (e.g. 'News') WordPress will try to use the following templates (in this order) taxonomy-{taxonomy}-{slug}.php taxonomy-{taxonomy}.php taxonomy.php archive.php index.php Modify ...


0

I was able to put this together from a similar question I found. If anyone else needs it: <?php $terms = get_terms( array( 'taxonomy' => 'features', 'hide_empty' => false ) ); if (!empty($terms) && ! is_wp_error( $terms )) { echo '<section>'; foreach ($terms as $term) { $class = has_term( $...


0

I would probably do it like this: $projects = get_posts([ 'posts_per_page' => -1, 'post_type' => 'project', 'order' => 'ASC', ]); $stories = get_posts([ 'posts_per_page' => -1, 'post_type' => 'storie', 'order' => 'ASC',// not rand! ]); function array_random_merge(array $a, array $b): ...


1

Try to get two different arrays of posts and loop through array A. Before get post data of A element get random element from array B. For example: $array_a = ['post_id_a1', 'post_id_a2', 'post_id_a3']; $array_b = ['post_id_b1', 'post_id_b2', 'post_id_b3']; foreach ( $array_a as $a_post_id ) { $is_b_should_displayed = mt_rand( 0, 1 ); if ( $...


0

Not sure the rewrite rule is good, but to answer the question about getting the post meta - you already have the post Object, so you don't need to run a function to get the global $post, which might also fail or be wrong - you can simply use: $metaText = get_post_meta( $post->ID, 'test_text_field', true); You will probably also want to debug the value of ...


0

Thanks for the reply. I've had another look into this and got something that works as a shortcode but not perfectly. Added the following to my functions.php file and using [showscats] as my shortcode in WPBakery it outputs the current custom post type taxonomies as a list. My CPT taxonomies being "project-type". The only issue is that it shows all ...


0

You could try something like this: // Get the taxonomy's terms $terms = get_terms( array( 'taxonomy' => 'your-taxonomy', 'hide_empty' => false, ) ); // Check if any term exists if ( ! empty( $terms ) && is_array( $terms ) ) { // Run a loop and print them all foreach ( $terms as $term ) { ?> <a ...


0

You can sort the results based on your custom table data by applying a custom filter to your existing query using the "posts_orderby" hook (untested example code): add_filter('posts_orderby', 'edit_posts_orderby'); function edit_posts_orderby($orderby_statement) { $orderby_statement = "views DESC"; return $orderby_statement; } ...


1

WP_Query does not have a built-in arg for querying posts by part of the post slug — and normally, one would search for similar posts by the post tag or category; however, you can use a custom arg along with the posts_where hook to query for similar posts by part of the slug. I.e. Use a custom SQL query, then use a hook to add that query to the SQL query ...


0

I discovered that if you press fast_edit before editing the page, there is an option to choose the superior page. While if you access edit this option is not present. The reason might be a collision between plugins or between a plugin and WordPress.


5

You can make an array of the post types you don't want and then check in_array() to see if they match before you output anything with them. <?php //You'll want to get at the actual name for My Templates. //My attempt is just a guess. $types_array = array( 'attachment' , 'elementor_library' ); $types = get_post_types( ['public' => true ...


1

You don't specify this, but if your lessons are being pulled in along with your arrangements then you must be using default WordPress posts for the Lessons... assuming that, here's what's happening in your code. On the second line when you're setting your query arguments ($args) you specify that you want BOTH the posts post type and your custom arrangements ...


1

It is not you, it is WordPress. I've just spent almost 2 hrs picking my hair debugging the same issue. Turns out meta_box_cb is only taken into account if the custom post type does NOT use Gutenberg editor - in your case if in the register_post_type() call the 'supports' array would not include 'editor'. Once Gutenberg is loaded, the metabox-es are not ...


0

Knowledge The filter title_save_pre runs before the post is written to the database, and also before any of its post meta is saved to the database. wp_get_object_terms at this point will be blank. To correct this you'll want to hook into save_post and update the post from there. save_post runs after the post has been saved to the database, and the in-...


0

WordPress hooks only work with global functions ( or public function inside a class ) - private or protected methods are not available due to their visibility level, so not available to the way WP calls actions or filters. What you are trying to do is tidy up your code using a class to contain all the functions ( called methods inside a class ), this seems ...


Top 50 recent answers are included