Hot answers tagged

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


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


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


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


2

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

Yes too early is probably why, the global $post variable is not populated yet. Try hooking to a later action (I think init at the very least): add_action('wp_enqueue_scripts','enqueue_product_styles'); function enqueue_product_styles() { if (get_post_type() == 'product'){ wp_enqueue_style( 'css_products.css', ...


1

If you want to change the order of an already existing query, you shouldn't create a new WP_Query object but instead use pre_get_posts to alter the existing query, which prevents multiple queries running unnecessarily. From the pre_get_posts docs: This hook is called after the query variable object is created, but before the actual query is run. ...


1

For anyone interested, this was the full solution to my problem. So far it works quite good. I use %postname% as the permalink structure and have my Custom Taxonomy working as my Brand and the Custom Post Type working as my Product. So my URL looks like this example.org/some-brand/some-product while I can display an overview on example.org/some-brand/. ...


1

You could try to "hijack" the following filter in the WP_List_Table class: /** * Filter the list of available list table views. * * The dynamic portion of the hook name, `$this->screen->id`, refers * to the ID of the current screen, usually a string. * * @since 3.5.0 * * @param array $views An array of available list table views. */ $views = ...


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


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


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

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.


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; ...


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( ...



Only top voted, non community-wiki answers of a minimum length are eligible