New answers tagged

0

You are using WP_query, try to change your loop to: <?php if ($wp_query->have_posts() ): while ($wp_query->have_posts() ) : $wp_query->the_post(); // Do stuff here endwhile; endif; wp_reset_postdata(); ?>


1

There is the action hook user_register that is called immediately after a user is added to the database. The user id is passed to the hook as an argument. You can use wp_insert_post to insert a new post in that action. You just need to get the relevant info from the user and add it to the post. You can add custom fields to the post you create by referencing ...


1

$my_query = new WP_Query('post_type=sliders&p=411'); if( $my_query->have_posts() ) { while ( $my_query->have_posts() ) : $my_query->the_post(); $slider_imgs = get_post_meta( get_the_ID(), 'slider_meta_key' ); foreach($slider_imgs as $slider_img) { echo '<img src="'.$saved_slider_meta.'">'; } endwhile; ...


1

EDIT: deleted incorrect information I see what you are missing now. Without knowing the specifics, I tried to point you in the right direction with this: $my_query = new WP_Query('post_type=sliders&p=411'); if( $my_query->have_posts() ) { while ( $my_query->have_posts() ) : $my_query->the_post(); // Get the specific meta data for ...


0

You'll need to set up a custom query for that post type, for example something like this: $args = array( 'post_type' => 'ADS', 'posts_per_page' => 10, 'orderby' => 'rand' ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); the_title(); echo '<div class="entry-content">'; the_content(); echo ...


1

Thank you all, guys. I've solved it this way: added $paged variable: $paged = ( get_query_var('page') ) ? get_query_var('page') : 1; (for main page you should use get_query_var('page'), for other pages - $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; ) And added a new argument for WP_Query: 'paged' => $paged My code now: function ...


2

Nothing would happen, everything would remain the same. Child themes inherit the functionality of the parent theme. Just a few notes All posts regardless of post type is stored in db, so they never "disappear" even when the post type does not exist anymore. Custom post types and custom taxonomies should be registered in a plugin to keep them available ...


0

I believe you can do something like this (not tested): if($_SERVER['REMOTE_ADDR']=="89.0.0.0" && $post->ID==15){ $post5 = get_post('5'); echo $post5->post_title; //Call custom meta using $post5->ID; } Update: If you'd like to replace the original object you can do the following: if($_SERVER['REMOTE_ADDR']=="89.0.0.0" && ...


0

An easy solution is to put following code inside style.css: a.read-more { display:none; } This targets <a class="read-more">


2

This Plugin gives you a list of posts for each Site already, but it does not exactly do what you want to do. Basically, it gives you a list of all posts in your network. What you need to do afterwards is sort them by site_id and create an output for that. I do not know if this is the best version - but as WP_Query returns an one-dimensional array, you need ...


1

the_posts_pagination uses global query and global query does not have pagination. So it is the correct behavior of WordPress. To overcome from this problem assign custom query to global query then after looping again restore the global query. function foo($args){ $post_type = $args['post_type']; global $wp_query; $original_query = $wp_query; ...


0

Add this code to your functions.php function mdc_remove_img($content) { $content = preg_replace("/<img[^>]+\>/i", "", $content); return $content; } add_filter( 'the_content', 'mdc_remove_img' );


-4

I figured out how to do this, Instead of using the_content(); Im now using the_excerpt(); and Im just changing the amount of characters it brings through!


1

When you create your custom post type, add 'hierarchical' => true to your post types options. That will make it behave like standard pages and let you use a parent/child, one -> many hierarchy.


2

The rule of thumb in wordpress development is that you should stick with the highest level API you can use. From software development perspective it helps you get a better documentation for your code and reduce the maintenance cost due to the backward compatibility policy. As CPTs have wrapper APIs in core and costume tables do not, it is easy to see that ...


1

First of all, before you do anything, make sure that you have flushed your permalinks, a 404 usually is a hint that you did not flush your permalinks after you created your custom post type the first time around. get_post_type_archive_link() will return the URL to the post type archive page, so you would do the following echo get_post_type_archive_link( ...


3

First, you should always use the WordPress AJAX methods, not a custom function for that. See AJAX in Plugins in the Codex. With that practice in mind, you can set up your request like this. Change the AJAX URL to <?php echo admin_url('admin-ajax.php'); ?> and add the actionyou want WordPress to execute in the next step to your data . ...


0

If your mu-plugin has options I would put the flush right after updating them: update_option( 'my_options', $values ); // Flush rules after install flush_rewrite_rules();


0

I've found a wordaround that "solves" the problem, but I'm not going to accept this as an answer until I'm not sure it is the only solution (which I suspect it is not). I can tell WP is not including the Ultimate VC Addons (UVCA from now on) CSS because my page does not contain any UVCA shortcode, or, at least, the initial page content doesn't. Shortcodes ...


0

Using the wp_dropdown_categories() function there's a parameter you can use called selected which you would assign the selected category ID. You should also standardize the name of your select so it's easier to save: $selected_id = get_post_meta( $post->ID, 'selected_tax', true ); wp_dropdown_categories( array( 'show_option_all' => 'Choose a ...


0

SOLVED with usage of $wp_rewrite you can add a new permalink structure add_action('init', 'my_custom_rewrite'); function my_custom_rewrite() { global $wp_rewrite; $wp_rewrite->add_permastruct('hardware', '/%customname%/', false); $wp_rewrite->add_permastruct('produkt', '/%customname%/', false); $wp_rewrite->flush_rules(); } then ...


0

I got it! For any one in the future with the same problem: ACF's get_field_object() apparently makes a WP_Query and doesn't clean up after so, since I called it for every post, I always got the same post after a certain point in the elaboration. I found the solution in this question. Some code for clarity: <?php while ( $query->have_posts() ) : ...


0

The re-slug plugin can be fixed to work with Wordpress 4 and up. Edit line 13 of re-slug.php to read: $return = str_replace('Edit</button>', 'Edit</button> <button type="button" id="re-slug" class="edit-slug button button-small hide-if-no-js" style="display:inherit;"><a href="#re-slug">Re-slug</a></button>', $return); ...


-1

According to what I understand is : In your taxonomy.php Add this code : $term = get_term_by( 'slug', get_query_var('term'), get_query_var('taxonomy') ); echo '<h2>Showing posts with topic : ' . $term->name .'</h2>'; This will result in showing "Showing post with topic : Cancer" Now for (all posts tagged with cancer already display ...


0

Have you tried using wp_reset_query() before the loop.


-1

See if this blog post gives you any help. https://premium.wpmudev.org/blog/removing-category-base-urls-wordpress/


0

You could use the default blog posts / custom post type and make use of the custom taxonomy and create a hierarchy of your list types. You can then achieve your page by using a shortcode to pull in your categories ( Salads) and children (Best Non-Veg Salads) . Within your shortcode you could use get_terms()


1

You may simply use register_post_type and register_taxonomy to do so: function add_cpt_salads(){ $labels = array( 'name' => __( 'Salads', 'your-text-domain' ), 'singular_name' => __( 'Salad', 'your-text-domain' ), 'menu_name' => __( 'Salads', 'your-text-domain' ...


-1

Try to change position : 'menu_position' => 18,


0

Below code works well if have multiple terms to show.:- echo get_the_term_list( $post->ID, 'styles', '<ul class="styles"><li>', ',</li><li>', '</li></ul>' );


0

You could try preg_match() if ( preg_match( "/thisfolder/", $imageURL) ) { echo 'your url here'; } See more here: http://php.net/manual/en/function.preg-match.php


0

Finally I found a solution for it. I set has_archive to true. Now both the feed and the archive page of CPT are active. To only disable the archive page of CPT, I use the following filter in the functions.php file: function AryanThemes_disable_cpt_archive_template(){ if ( is_post_type_archive('cpt') ) { global $wp_query; ...


2

The post's title isn't meta data, it's in the main post table. You can order by title with: 'orderby' => 'title' You would specify a meta key / order by meta value if the field were custom data stored in the post meta table.


0

To find projects happening within a range of dates, there are 3 cases you have to account for: A project starts within the range A project ends within the range A project starts before the range and ends after the range You can test for these 3 cases separately with an OR meta query and 1 nested AND: 'meta_query' => array( 'relation' => 'OR', ...


1

Set the feeds argument of rewrite to true to generate feed rewrite rules. It defaults to whatever has_archive is set to if nothing is explicitly passed. $args = array( 'has_archive' => false, 'rewrite' => array( 'feeds' => true ), // your other args... );


0

First, do not use query_posts! (Why not? That is why!) Second, if your custom fields (CF) are saved in the Ymd-form (you are sure about that, yes?!), everything should be fine, even if you do not define the "type" as "date". Reading through several discussions on SE, etc. it seems to be better just to avoid the "date"-type, if you are not comparing a ...


0

Simply order by parent... $terms = wp_get_post_terms( $ID , $tax, array( 'orderby' => 'parent', 'order' => 'ASC' ) ); $myparent = $terms[0];


0

I copied your code as-is above, pasted it into the twentysixteen theme, and changed just the post type rewrite slug from review/%brand% to %brand%. This resulted in both the term archive and review posts having your desired URL structure and successfully displaying. Now the bad news is that the rewrite rules generated for the taxonomy and post type stomp ...


0

It turns out the Wordpress permalink structure works perfectly well for custom types, e.g. example.com/recipes/lunch/sandwich/. This works exactly as expected if you set 'hierarchical' => true. What I was originally trying to do was unnecessarily difficult to execute, and requires properly setting up a custom permalink structure to avoid 404 errors. I ...


1

The code you need to use here has some steps. First you need to create e metabox on your custom post type edit.php which will list all your posts of test_chapter post type. Then you have to hook the save_post action so you set the parent of your edited post to the chosen "test_chapter". The best way is to connect these two post types as post meta and not as ...


-2

First you create test_book function and call add_action() function to initialize this function. Example: add_action('admin_menu', 'test_book'); Then after you define test_book() function functionality, for adding menu and sub-menu you declare your function test_book() like this manner.... function test_book(){ add_menu_page( "Books", "Books", ...


1

Any template file must be in the current active theme folder. If they are in a different location, they won't be automatically loaded, instead you need to code and modify the template file location determined by WordPress template system: add_filter( 'template_include', 'envento_type_templates', 99 ); function portfolio_page_template( $template ) { if ...


0

Looks like I found a snippet that do exactly that. It's from Daniel Bachhuber, the API developer. add_filter( 'rest_authentication_errors', function( $result ) { if ( ! empty( $result ) ) { return $result; } if ( ! is_user_logged_in() ) { return new WP_Error( 'restx_logged_out', 'Sorry, you must be logged in to make a request.', ...


0

While Pieter solved the issue elegant and comprehensively with no doubt, I finally went with another solution, which I want to share here, too. Maybe some folks are facing similiar issues in the time to come. For custom post type definition as described in my question I used a plugin called Pods. As the plugin devs and community are likely to handle custom ...


0

This is in my single.php: <div class="sp-article-author-box-bg"> <div class="sp-article-author-box"> <span class="spbox-right"> <div class="spbox-bio"> <?php if ( $string = xprofile_get_field_data( 'About', get_the_author_meta('ID') ) ) { echo ...


-1

Check below code.. for adding capabilities to administrator and editor... This code might work if you don't want to use any plugin. function plugin_main_functions(){ register_post_type('teachers', array( 'labels' => array( 'name'=>__('Teachers List', 'Teachers'), 'add_new' => __('add new teacher', 'Teachers'), 'add_new_item' => ...


1

Capabilities are stored in database, that is why they keep active even if you remove your function. Capabilities need to be expressly removed: $admin = get_role('author'); $admin->remove_cap( 'edit_teacher' ); And, because they are stored in database, you should stop adding them in every page load (as you are doing in init event). Usually, you should ...


0

This is adapted from code someone else wrote, and which I benefitted from too long ago to know where it came from (if the person who originally wrote it is reading this, thanks again). It works for your request: <?php $catPost = get_posts('cat=888&posts_per_page=-1000'); foreach ($catPost as $post) : setup_postdata($post); ?> <a ...


0

If you are manually registering your custom taxonomy via register_taxonomy then you can pass in arguments to control where the metabox appears. In the example below setting show_ui to false would completely remove the metabox from the edit screen, the quick edit screen, and the admin menu. But if you set show_ui to true you can achieve more nuanced control ...


3

@PieterGoosen is cool, and still awake like me and answering like boss. To simplify his code and make it work to this specifically without a bunch of junk on your page: /** * Pieter Goosen writes awesome code */ add_filter( 'register_post_type_args', 'change_capabilities_of_the_custom_css_js_posttype' , 10, 2 ); function ...



Top 50 recent answers are included